diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3029b69607c3bf19b6906f35f6dd4c8fa1996a01..4b0abf865885ce69726092a064a39380fba063d9 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 00fa4417cfbef8673c47c86eb24033fcd97056a8..13ffd65dc52dd652f27a47b20234ca2ddb01a62a 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 2bd6f4fda009061e5236b75f39ee67fd4c1d8a5b..8ce44f61a0dbc1c71dad87809a339d726c27780c 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 e30e685a6029905a821569a055989ce7f651b9b4..8e654318284add1d9d097f34014be7aa331f6cb8 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 03a2e4c0951faceff5f4ad24cad0aca4a2cb050f..c1d8ffd4b9b3900028dcd40939ccdc1b5b33d8d2 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 a1284b9ce4008fc518063b21d3c2738ee3e3fdb8..4160f5fd05968644705337c7c8f70a56e83d3306 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 4dd4aa04e7c7a030e1771e3a0ac76903654357d1..40f0cacc18098af36ea40f0a89cf7817407250b2 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: