Skip to content

Commit

Permalink
AbbasHussein
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbas1Hussein committed Aug 5, 2023
1 parent 36fea47 commit 6dbf7a4
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 32 deletions.
36 changes: 18 additions & 18 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2023] [Abbas Hussein]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To use the oauth2_manager package with a specific provider, you will need to con
To use the Authorization Code Grant flow, first create an instance of the `OAuth2Configuration` class and pass in the parameters:

```dart
import 'package:oauth2_manager/oauth_manager.dart';
import 'package:oauth2_manager/oauth2_manager.dart';
final oauth2Configuration = OAuth2Configuration(
clientID: '<client ID>',
Expand All @@ -42,7 +42,7 @@ final credentials = await OAuth2.login(
// Open the authorization URL in the user's browser
// Example: await launch('$uri');
},
redirectPage: '<the page to display after authorization>',
redirectPage: '<the page.html to display after authorization>',
contentType: '<content type of redirectPage>',
);
```
Expand Down
30 changes: 29 additions & 1 deletion example/oauth2_manager_example.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:oauth2_manager/oauth_manager.dart';
import 'package:oauth2_manager/oauth2_manager.dart';

main() async {
/// Google
Expand Down Expand Up @@ -64,4 +64,32 @@ main() async {
tokenEndpoint: 'https://api.amazon.com/auth/o2/token',
scopes: ['<scope>'],
);


String authorizationSuccessHtml = '''
<!DOCTYPE html>
<html>
<head>
<title>Authorization Success</title>
</head>
<body>
<h1>Authorization Successful</h1>
<p>You have successfully authorized the application.</p>
<!-- You can add more content or elements here as needed -->
</body>
</html>
''';

await OAuth2.login(
googleConfiguration,
redirect: (uri) async {
print(uri.toString());
// Open the authorization URL in the user's browser
// Example: await launch('$uri');
},
redirectPage: authorizationSuccessHtml,
contentType: 'text/html',
);


}
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/src/oauth.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:oauth2_manager/oauth_manager.dart';
import 'package:oauth2_manager/oauth2_manager.dart';
import 'package:oauth2_manager/src/typedef.dart';

import 'oauth2_manager.dart';
Expand Down
12 changes: 6 additions & 6 deletions lib/src/oauth2_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:oauth2/oauth2.dart' as oauth2;
import 'package:oauth2_manager/oauth_manager.dart';
import 'package:oauth2_manager/oauth2_manager.dart';
import 'package:oauth2_manager/src/typedef.dart';

/// An abstract class for managing OAuth2 authentication.
Expand All @@ -12,7 +12,7 @@ abstract class BaseOAuth2Manager {

/// Starts a local server and listens for the redirect URI.
///
/// The `redirectPage` argument is the HTML page to display to the user after the redirect URI is received.
/// The `redirectPage` argument is the HTML page.html to display to the user after the redirect URI is received.
/// The `contentType` argument is the content type of the response.
///
/// Returns a `Map<String, String>` of the query parameters in the redirect URI.
Expand All @@ -35,7 +35,7 @@ abstract class BaseOAuth2Manager {
}

/// This class extends the BaseOAuth2Manager class and implements the OAuth2 Authorization Code Grant flow.
/// It uses a HttpServer to receive the authorization code and a redirect function to open the authorization page in the user's browser.
/// It uses a HttpServer to receive the authorization code and a redirect function to open the authorization page.html in the user's browser.
class OAuth2Manager extends BaseOAuth2Manager {
/// The OAuth2 configuration.
final OAuth2Configuration _configuration;
Expand All @@ -45,10 +45,10 @@ class OAuth2Manager extends BaseOAuth2Manager {
}) : _configuration = configuration;

/// This method initiates the OAuth2 flow by creating a HttpServer to receive the authorization code,
/// opening the authorization page in the user's browser, and handling the authorization response to obtain an OAuth2 token.
/// opening the authorization page.html in the user's browser, and handling the authorization response to obtain an OAuth2 token.
///
/// [redirect] The function used to open the authorization page in the user's browser.
/// [redirectPage] The page to display to the user after the redirect URI is received.
/// [redirect] The function used to open the authorization page.html in the user's browser.
/// [redirectPage] The page.html to display to the user after the redirect URI is received.
/// [contentType] The content type of the redirectPage.
Future<oauth2.Credentials> login({
required RedirectUri redirect,
Expand Down
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ version: 1.0.0
repository: https://github.com/Abbas1Hussein/oauth2_manager

environment:
sdk: '>=2.19.0 <3.0.0'
sdk: '>=2.19.0 <4.0.0'

dependencies:
oauth2: ^2.0.1
oauth2: ^2.0.2
http: ^1.1.0

dev_dependencies:
lints: ^2.0.1
test: ^1.24.2
lints: ^2.1.1
test: ^1.24.5

0 comments on commit 6dbf7a4

Please sign in to comment.