Skip to content

Commit

Permalink
AbbasHussein
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbas1Hussein committed May 8, 2023
1 parent 706390e commit 536c82e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
78 changes: 54 additions & 24 deletions example/oauth2_manager_example.dart
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
import 'package:oauth2_manager/oauth_manager.dart';

main() async {
/// Google
final googleConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
tokenEndpoint: 'https://oauth2.googleapis.com/token',
scopes: ['<scope>'],
);

/// Facebook
final facebookConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
authorizationEndpoint: 'https://www.facebook.com/v12.0/dialog/oauth',
tokenEndpoint: 'https://graph.facebook.com/v12.0/oauth/access_token',
scopes: ['<scope>'],
);

/// Twitter
final twitterConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
tokenEndpoint: 'https://api.twitter.com/oauth/access_token',
scopes: ['<scope>'],
);

final oauth2Configuration = OAuth2Configuration(
/// Github
final githubConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
tokenEndpoint: '<token endpoint>',
authorizationEndpoint: '<authorization endpoint>',
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
tokenEndpoint: 'https://github.com/login/oauth/access_token',
scopes: ['<scope>'],
);

final credentials = await OAuth2.login(
oauth2Configuration,
redirect: (uri) async {
// Open the authorization URL in the user's browser
// Example: await launch('$uri');
},
redirectPage: '<the page to display after authorization>',
contentType: '<content type of redirectPage>',
/// LinkedIn
final linkedInConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
authorizationEndpoint: 'https://www.linkedin.com/oauth/v2/authorization',
tokenEndpoint: 'https://www.linkedin.com/oauth/v2/accessToken',
scopes: ['<scope>'],
);

// credentials.accessToken
// credentials.refreshToken,
// credentials.idToken,
// credentials.expiration
// credentials.isExpired
// credentials.canRefresh
/// Microsoft
final microsoftConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
authorizationEndpoint:
'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
tokenEndpoint: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
scopes: ['<scope>'],
);

final newCredentials = await OAuth2.getRefreshToken(
credentials.refreshToken!,
newScopes: ['<scope>'],
clientID: oauth2Configuration.clientID,
clientSecret: oauth2Configuration.clientSecret!,
tokenEndpoint: oauth2Configuration.authorizationEndpoint,
/// Amazon
final amazonConfiguration = OAuth2Configuration(
clientID: '<client ID>',
clientSecret: '<client secret>',
authorizationEndpoint: 'https://www.amazon.com/ap/oa',
tokenEndpoint: 'https://api.amazon.com/auth/o2/token',
scopes: ['<scope>'],
);
}
}
3 changes: 1 addition & 2 deletions lib/oauth_manager.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export 'package:oauth2_manager/src/oauth2_manager.dart';
export 'package:oauth2_manager/src/oauth.dart';
export 'package:oauth2_manager/src/oauth2_configuration.dart';
export 'package:oauth2/oauth2.dart';
export 'package:oauth2/oauth2.dart' show Credentials;

0 comments on commit 536c82e

Please sign in to comment.