Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROPOSAL] debug flag #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/flutter_web_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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');
}
Expand All @@ -40,6 +42,7 @@ class FlutterWebAuth {
WidgetsBinding.instance.addObserver(_resumedObserver);
return await _channel.invokeMethod('authenticate', <String, dynamic>{
'url': url,
'debug': debug ?? false,
'callbackUrlScheme': callbackUrlScheme,
'preferEphemeral': preferEphemeral ?? false,
}) as String;
Expand Down
7 changes: 4 additions & 3 deletions lib/src/flutter_web_auth_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -27,10 +28,10 @@ class FlutterWebAuthPlugin {
}
}

static Future<String> _authenticate(String url) async {
static Future<String> _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;
Expand Down