Skip to content

Commit

Permalink
Add contextArgs parameter
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
ThexXTURBOXx committed Apr 11, 2023
1 parent a0a8702 commit 5f4448e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions flutter_web_auth_2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.3

- 🌹 Add `contextArgs` for web implementations (See [#40](https://github.com/ThexXTURBOXx/flutter_web_auth_2/issues/40))

## 2.1.2

- 🐛 Downgrade Kotlin to fix some compatibility issues
Expand Down
4 changes: 3 additions & 1 deletion flutter_web_auth_2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ On the web platform, an endpoint must be created that captures the callback URL
```html
<!DOCTYPE html>
<title>Authentication complete</title>
<p>Authentication is complete. If this does not happen automatically, please close the window.
<p>Authentication is complete. If this does not happen automatically, please close the window.</p>
<script>
window.opener.postMessage({
'flutter-web-auth-2': window.location.href
Expand All @@ -146,6 +146,8 @@ The redirect URL passed to the authentication service must be the same as the UR

For the Sign in with Apple in web_message response mode, postMessage from https://appleid.apple.com is also captured, and the authorization object is returned as a URL fragment encoded as a query string (for compatibility with other providers).

If you want to pass additional parameters to the URL open call, you can do so in the `authenticate` function using the parameter `contextArgs`.

### Windows and Linux

There is still a limitation that the callback URL scheme must start with `http://localhost:{port}`.
Expand Down
5 changes: 5 additions & 0 deletions flutter_web_auth_2/lib/flutter_web_auth_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ class FlutterWebAuth2 {
/// [redirectOriginOverride] is used to override the origin of the redirect
/// URL. This is useful for cases where the redirect URL is not on the same
/// domain (ex. local testing). Only supported in web.
///
/// [contextArgs] is used to pass additional settings for the URL open call
/// on the web platform.
static Future<String> authenticate({
required String url,
required String callbackUrlScheme,
bool? preferEphemeral,
String? redirectOriginOverride,
List contextArgs = const [],
}) async {
assert(
redirectOriginOverride == null || kDebugMode,
Expand All @@ -83,6 +87,7 @@ class FlutterWebAuth2 {
callbackUrlScheme: callbackUrlScheme,
preferEphemeral: preferEphemeral ?? false,
redirectOriginOverride: redirectOriginOverride,
contextArgs: contextArgs,
);
}

Expand Down
1 change: 1 addition & 0 deletions flutter_web_auth_2/lib/src/flutter_web_auth_2_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FlutterWebAuth2LinuxPlugin extends FlutterWebAuth2Platform {
required String callbackUrlScheme,
required bool preferEphemeral,
String? redirectOriginOverride,
List contextArgs = const [],
}) async {
// Validate callback url
final callbackUri = Uri.parse(callbackUrlScheme);
Expand Down
3 changes: 2 additions & 1 deletion flutter_web_auth_2/lib/src/flutter_web_auth_2_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class FlutterWebAuth2WebPlugin extends FlutterWebAuth2Platform {
required String callbackUrlScheme,
required bool preferEphemeral,
String? redirectOriginOverride,
List contextArgs = const [],
}) async {
context.callMethod('open', [url]);
context.callMethod('open', <dynamic>[url] + contextArgs);
await for (final MessageEvent messageEvent in window.onMessage) {
if (messageEvent.origin == (redirectOriginOverride ?? Uri.base.origin)) {
final flutterWebAuthMessage = messageEvent.data['flutter-web-auth-2'];
Expand Down
1 change: 1 addition & 0 deletions flutter_web_auth_2/lib/src/flutter_web_auth_2_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FlutterWebAuth2WindowsPlugin extends FlutterWebAuth2Platform {
required String callbackUrlScheme,
required bool preferEphemeral,
String? redirectOriginOverride,
List contextArgs = const [],
}) async {
// Validate callback url
final callbackUri = Uri.parse(callbackUrlScheme);
Expand Down
2 changes: 1 addition & 1 deletion flutter_web_auth_2/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_web_auth_2
description: Flutter plugin for authenticating a user with a web service.
version: 2.1.2
version: 2.1.3
homepage: https://github.com/ThexXTURBOXx/flutter_web_auth_2
repository: https://github.com/ThexXTURBOXx/flutter_web_auth_2
issue_tracker: https://github.com/ThexXTURBOXx/flutter_web_auth_2/issues
Expand Down
4 changes: 4 additions & 0 deletions flutter_web_auth_2_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.3

- 🌹 Add `contextArgs` for web implementations (See [#40](https://github.com/ThexXTURBOXx/flutter_web_auth_2/issues/40))

## 2.1.0

- 🌹 Update linter rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ abstract class FlutterWebAuth2Platform extends PlatformInterface {
required String callbackUrlScheme,
required bool preferEphemeral,
String? redirectOriginOverride,
List contextArgs = const [],
}) =>
_instance.authenticate(
url: url,
callbackUrlScheme: callbackUrlScheme,
preferEphemeral: preferEphemeral,
redirectOriginOverride: redirectOriginOverride,
contextArgs: contextArgs,
);

Future clearAllDanglingCalls() => _instance.clearAllDanglingCalls();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class FlutterWebAuth2MethodChannel extends FlutterWebAuth2Platform {
required String callbackUrlScheme,
required bool preferEphemeral,
String? redirectOriginOverride,
List contextArgs = const [],
}) async =>
await channel.invokeMethod<String>('authenticate', <String, dynamic>{
'url': url,
'callbackUrlScheme': callbackUrlScheme,
'preferEphemeral': preferEphemeral,
'redirectOriginOverride': redirectOriginOverride,
'contextArgs': contextArgs,
}) ??
'';

Expand Down
2 changes: 1 addition & 1 deletion flutter_web_auth_2_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_web_auth_2_platform_interface
description: A common platform interface for the flutter_web_auth_2 plugin.
version: 2.1.0
version: 2.1.3
homepage: https://github.com/ThexXTURBOXx/flutter_web_auth_2
repository: https://github.com/ThexXTURBOXx/flutter_web_auth_2
issue_tracker: https://github.com/ThexXTURBOXx/flutter_web_auth_2/issues
Expand Down

0 comments on commit 5f4448e

Please sign in to comment.