From 0d569ce3a7217648233a3867e4d2b1fd9e37c7cc Mon Sep 17 00:00:00 2001 From: Arina Date: Thu, 15 Dec 2022 21:25:59 +0300 Subject: [PATCH 1/2] debug flag for test without deploy --- lib/src/flutter_web_auth_web.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/flutter_web_auth_web.dart b/lib/src/flutter_web_auth_web.dart index f916fab5..9d6f8726 100644 --- a/lib/src/flutter_web_auth_web.dart +++ b/lib/src/flutter_web_auth_web.dart @@ -18,7 +18,8 @@ class FlutterWebAuthPlugin { switch (call.method) { case 'authenticate': final String url = call.arguments['url']; - return _authenticate(url); + final bool debug = call.arguments['debug']; + return _authenticate(url, debug); default: throw PlatformException( code: 'Unimplemented', @@ -27,10 +28,10 @@ class FlutterWebAuthPlugin { } } - static Future _authenticate(String url) async { + static Future _authenticate(String url, bool debug) async { context.callMethod('open', [url]); await for (MessageEvent messageEvent in window.onMessage) { - if (messageEvent.origin == Uri.base.origin) { + if (messageEvent.origin == Uri.base.origin || debug) { final flutterWebAuthMessage = messageEvent.data['flutter-web-auth']; if (flutterWebAuthMessage is String) { return flutterWebAuthMessage; From 0e8f41756b2d88bf6a6e0907250a62f5ac0e5ec4 Mon Sep 17 00:00:00 2001 From: Arina Date: Thu, 15 Dec 2022 21:29:38 +0300 Subject: [PATCH 2/2] [debug] flag [debug] flag - used for avoid comparing Url.base.origin and messageEvent.origin that gives us opportunity to test without deploy (ex. deployed back example.com and local flutter app localhost) --- lib/flutter_web_auth.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/flutter_web_auth.dart b/lib/flutter_web_auth.dart index 0f923b4a..4e09a767 100644 --- a/lib/flutter_web_auth.dart +++ b/lib/flutter_web_auth.dart @@ -31,7 +31,9 @@ class FlutterWebAuth { /// /// [callbackUrlScheme] should be a string specifying the scheme of the url that the page will redirect to upon successful authentication. /// [preferEphemeral] if this is specified as `true`, an ephemeral web browser session will be used where possible (`FLAG_ACTIVITY_NO_HISTORY` on Android, `prefersEphemeralWebBrowserSession` on iOS/macOS) - static Future authenticate({required String url, required String callbackUrlScheme, bool? preferEphemeral}) async { + /// + /// [debug] flag - used for avoid comparing Url.base.origin and messageEvent.origin that gives us opportunity to test without deploy (ex. deployed back example.com and local flutter app localhost) + static Future authenticate({required String url, required String callbackUrlScheme, bool? preferEphemeral, bool? debug}) async { if (!_schemeRegExp.hasMatch(callbackUrlScheme)) { throw ArgumentError.value(callbackUrlScheme, 'callbackUrlScheme', 'must be a valid URL scheme'); } @@ -40,6 +42,7 @@ class FlutterWebAuth { WidgetsBinding.instance.addObserver(_resumedObserver); return await _channel.invokeMethod('authenticate', { 'url': url, + 'debug': debug ?? false, 'callbackUrlScheme': callbackUrlScheme, 'preferEphemeral': preferEphemeral ?? false, }) as String;