From 70ea45764e7db2bebb5660a0a5ad503e4ca27d4c Mon Sep 17 00:00:00 2001 From: igorwork <markin.io210@gmail.com> Date: Thu, 18 Jul 2019 11:31:12 +0300 Subject: [PATCH] Integrate OAuth2 lib --- android/app/src/main/AndroidManifest.xml | 25 +++++++++++++++++++ android/app/src/main/res/values/styles.xml | 9 +++++++ android/gradle.properties | 2 ++ lib/app.dart | 4 ++-- lib/screens/home.dart | 28 ++++++++++++++++++++-- pubspec.lock | 21 ++++++++++++++++ pubspec.yaml | 2 ++ 7 files changed, 87 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3029b69..4b0abf8 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,9 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" package="com.vereign.mobile_app"> + <uses-permission android:name="android.permission.INTERNET" /> + <!-- io.flutter.app.FlutterApplication is an android.app.Application that calls FlutterMain.startInitialization(this); in its onCreate method. In most cases you can leave this as-is, but you if you want to provide @@ -31,6 +34,7 @@ <intent-filter> <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data @@ -38,5 +42,26 @@ android:host="app.vereign.com" /> </intent-filter> </activity> + + <activity + android:name="net.openid.appauth.RedirectUriReceiverActivity" + tools:node="replace"> + <intent-filter> + <action android:name="android.intent.action.VIEW" /> + + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + + <data + android:scheme="app" + android:host="com.vereign.app" + android:path="/oauth2"/> + </intent-filter> + </activity> + + <activity + android:name="github.showang.flutterappauthwrapper.OAuthActivity" + android:configChanges="orientation|screenSize" + android:theme="@style/Theme.AppCompat.Translucent" /> </application> </manifest> diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index 00fa441..13ffd65 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -5,4 +5,13 @@ Flutter draws its first frame --> <item name="android:windowBackground">@drawable/launch_background</item> </style> + + <style name="Theme.AppCompat.Translucent" parent="@style/Theme.AppCompat.NoActionBar"> + <item name="android:windowNoTitle">true</item> + <item name="android:windowBackground">@android:color/transparent</item> + <item name="android:colorBackgroundCacheHint">@null</item> + <item name="android:windowIsTranslucent">true</item> + <item name="android:windowAnimationStyle">@android:style/Animation</item> + <item name="android:statusBarColor">@android:color/transparent</item> + </style> </resources> diff --git a/android/gradle.properties b/android/gradle.properties index 2bd6f4f..8ce44f6 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M +android.enableJetifier=true +android.useAndroidX=true diff --git a/lib/app.dart b/lib/app.dart index e30e685..8e65431 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -17,7 +17,7 @@ class App extends StatefulWidget { class _AppState extends State<App> { StreamSubscription _sub; - String _appMode = "oauth"; + String _appMode = "app"; @override initState() { @@ -51,7 +51,7 @@ class _AppState extends State<App> { } updateAppMode(uri) { - + log("Uri ${uri?.toString()}"); if (uri?.path == "/oauth2") { setState(() { _appMode = "oauth"; diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 03a2e4c..c1d8ffd 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_web_browser/flutter_web_browser.dart'; +import 'package:flutter_app_auth_wrapper/flutter_app_auth_wrapper.dart'; import 'dart:developer'; class Home extends StatefulWidget { @@ -10,8 +11,15 @@ class Home extends StatefulWidget { _HomeState createState() => _HomeState(); } +String clientId = "222222"; +String clientSecret = "22222222"; + +String redirectURL = "app://com.vereign.app/oauth2"; +String authEndpoint = "https://gospodinbodurov.dev.vereign.com/api/oauth2/authorize"; +String tokenEndpoint = "https://gospodinbodurov.dev.vereign.com/api/oauth2/token"; + class _HomeState extends State<Home> { - final _links = ['vereign://app.vereign.com', 'vereign://app.vereign.com/oauth2', 'https://rosengeorgiev.dev.vereign.com', 'https://igormarkin.dev.vereign.com', 'https://gospodinbodurov.dev.vereign.com']; + final _links = ['vereign://app.vereign.com', 'vereign://app.vereign.com/oauth2', 'testredirect://app.vereign.com', 'https://igormarkin.dev.vereign.com', 'https://gospodinbodurov.dev.vereign.com']; @override initState() { @@ -31,10 +39,26 @@ class _HomeState extends State<Home> { } showMode(mode) { + log(mode); if (mode == "app") { FlutterWebBrowser.openWebPage(url: 'https://app.vereign.com', androidToolbarColor: Colors.deepPurple); } else if (mode == "oauth") { - FlutterWebBrowser.openWebPage(url: 'https://app.vereign.com/oauth2', androidToolbarColor: Colors.deepPurple); + FlutterAppAuthWrapper.startAuth( + AuthConfig( + clientId: clientId, + clientSecret: clientSecret, + redirectUrl: redirectURL, + state: "login", + prompt: "consent", + endpoint: AuthEndpoint( + auth: authEndpoint, token: tokenEndpoint), + scopes: [ + "user_account_status", + "user_territory", + "user_profile" + ], + ), + ); } } diff --git a/pubspec.lock b/pubspec.lock index a1284b9..4160f5f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -41,6 +41,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_app_auth_wrapper: + dependency: "direct main" + description: + name: flutter_app_auth_wrapper + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1+3" flutter_test: dependency: "direct dev" description: flutter @@ -53,6 +60,20 @@ packages: relative: true source: path version: "0.11.0" + http: + dependency: "direct main" + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.0+2" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.3" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4dd4aa0..40f0cac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: # Use path: ./deps/flutter_web_browser uni_links: 0.2.0 + http: ^0.12.0 + flutter_app_auth_wrapper: ^0.1.1+3 dev_dependencies: flutter_test: -- GitLab