Skip to content

Commit

Permalink
- First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luis901101 committed Dec 6, 2021
0 parents commit 4c1d408
Show file tree
Hide file tree
Showing 16 changed files with 686 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .flutter-plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a generated file; do not edit or check into version control.
webview_flutter=/Users/krrigan/Flutter/SDK/.pub-cache/hosted/pub.dartlang.org/webview_flutter-2.3.1/
webview_flutter_android=/Users/krrigan/Flutter/SDK/.pub-cache/hosted/pub.dartlang.org/webview_flutter_android-2.4.0/
webview_flutter_wkwebview=/Users/krrigan/Flutter/SDK/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.5.0/
1 change: 1 addition & 0 deletions .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"webview_flutter_wkwebview","path":"/Users/krrigan/Flutter/SDK/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.5.0/","dependencies":[]}],"android":[{"name":"webview_flutter_android","path":"/Users/krrigan/Flutter/SDK/.pub-cache/hosted/pub.dartlang.org/webview_flutter_android-2.4.0/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"webview_flutter","dependencies":["webview_flutter_android","webview_flutter_wkwebview"]},{"name":"webview_flutter_android","dependencies":[]},{"name":"webview_flutter_wkwebview","dependencies":[]}],"date_created":"2021-12-06 16:42:01.600814","version":"2.7.0-3.1.pre"}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: fc7015e35aac7ab785e7ae15a47db5c9e669ec7f
channel: beta

project_type: package
30 changes: 30 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.packages
.pub-cache/
.pub/
/build/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2016, the Dart project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
1 change: 1 addition & 0 deletions check-publish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flutter pub publish --dry-run $1
4 changes: 4 additions & 0 deletions lib/oauth_webauth.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library oauth_webauth;

export 'package:oauth_webauth/src/oauth_web_view.dart';
export 'package:oauth_webauth/src/oauth_web_screen.dart';
140 changes: 140 additions & 0 deletions lib/src/oauth_web_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

import 'package:flutter/material.dart';
import 'package:oauth2/oauth2.dart';
import 'package:oauth_webauth/src/oauth_web_view.dart';

class OAuthWebScreen extends StatelessWidget {

static Future? start({
Key? key,
required BuildContext context,
required String authorizationEndpointUrl,
required String tokenEndpointUrl,
required String redirectUrl,
required String clientId,
String? clientSecret,
List<String>? scopes,
String? loginHint,
List<String>? promptValues,
ValueChanged<Credentials>? onSuccess,
ValueChanged<dynamic>? onError,
VoidCallback? onCancel,
ThemeData? themeData,
Map<String, String>? tooltipLocales
}) => Navigator.push(context,
MaterialPageRoute(builder: (context) =>
OAuthWebScreen(
authorizationEndpointUrl: authorizationEndpointUrl,
tokenEndpointUrl: tokenEndpointUrl,
redirectUrl: redirectUrl,
clientId: clientId,
clientSecret: clientSecret,
scopes: scopes,
loginHint: loginHint,
promptValues: promptValues,
onSuccess: onSuccess,
onError: onError,
onCancel: onCancel,
themeData: themeData,
tooltipLocales: tooltipLocales,
)
));


final String authorizationEndpointUrl;
final String tokenEndpointUrl;
final String redirectUrl;
final String clientId;
final String? clientSecret;
final List<String>? scopes;
final String? loginHint;
final List<String>? promptValues;

/// This function will be called when user successfully authenticates.
/// It will receive the Oauth Credentials
final ValueChanged<Credentials>? onSuccess;

/// This function will be called if any error occurs.
/// It will receive the error data which could be some Exception or Error
final ValueChanged<dynamic>? onError;

/// This function will be called when user cancels authentication.
final VoidCallback? onCancel;

final ThemeData? themeData;
final Map<String, String>? tooltipLocales;

late final BuildContext context;
final paymentViewStateKey = GlobalKey<OAuthWebViewState>();

OAuthWebScreen({
Key? key,
required this.authorizationEndpointUrl,
required this.tokenEndpointUrl,
required this.redirectUrl,
required this.clientId,
this.clientSecret,
this.scopes,
this.loginHint,
this.promptValues,
this.onSuccess,
this.onError,
this.onCancel,
this.themeData,
this.tooltipLocales,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Builder(
builder: (context) {
this.context = context;
return Scaffold(
body: WillPopScope(
onWillPop: onBackPressed,
child: OAuthWebView(
key: paymentViewStateKey,
authorizationEndpointUrl: authorizationEndpointUrl,
tokenEndpointUrl: tokenEndpointUrl,
clientId: clientId,
clientSecret: clientSecret,
redirectUrl: redirectUrl,
scopes: scopes,
loginHint: loginHint,
promptValues: promptValues,
onSuccess: _onSuccess,
onError: _onError,
onCancel: _onCancel,
themeData: themeData,
tooltipLocales: tooltipLocales,
),
),
);
},
);
}

void _onSuccess(Credentials credentials) {
Navigator.pop(context, credentials);
onSuccess?.call(credentials);
}

void _onError(dynamic error) {
Navigator.pop(context, error);
onError?.call(error);
}

void _onCancel() {
Navigator.pop(context);
onCancel?.call();
}

Future<bool> onBackPressed() async {
if(!((await paymentViewStateKey.currentState?.onBackPressed()) ?? false)) {
return false;
}
onCancel?.call();
return true;
}

}
Loading

0 comments on commit 4c1d408

Please sign in to comment.