Skip to content

Commit

Permalink
Add support for passing parameters onLoad (#363)
Browse files Browse the repository at this point in the history
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
  • Loading branch information
frederikprijck and Widcket authored Dec 6, 2023
1 parent 41b7dd8 commit 8a7aa05
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
9 changes: 9 additions & 0 deletions auth0_flutter/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ final credentials = await auth0
<details>
<summary>Web</summary>

Custom parameters can be configured globally.

```dart
await auth0Web.onLoad(
parameters: {'connection': 'github'});
```

Custom parameters can be configured when calling `loginWithRedirect`. Any globally configured parameter (passed to `onLoad()`) can be overriden when passing the same custom parameter to `loginWithRedirect`.

```dart
await auth0Web.loginWithRedirect(
redirectUrl: 'http://localhost:3000',
Expand Down
6 changes: 4 additions & 2 deletions auth0_flutter/lib/auth0_flutter_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class Auth0Web {
final bool? useRefreshTokens,
final bool? useRefreshTokensFallback,
final String? audience,
final Set<String>? scopes}) async {
final Set<String>? scopes,
final Map<String, String> parameters = const {}}) async {
await Auth0FlutterWebPlatform.instance.initialize(
ClientOptions(
account: _account,
Expand All @@ -68,7 +69,8 @@ class Auth0Web {
useRefreshTokens: useRefreshTokens,
useRefreshTokensFallback: useRefreshTokensFallback,
audience: audience,
scopes: scopes),
scopes: scopes,
parameters: parameters),
_userAgent);

if (await hasValidCredentials()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ extension ClientOptionsExtension on ClientOptions {
useFormData: useFormData,
useRefreshTokens: useRefreshTokens,
useRefreshTokensFallback: useRefreshTokensFallback,
authorizationParams: JsInteropUtils.stripNulls(AuthorizationParams(
audience: audience,
scope: scopes?.isNotEmpty == true ? scopes?.join(' ') : null)));
authorizationParams: JsInteropUtils.stripNulls(
JsInteropUtils.addCustomParams(
AuthorizationParams(
audience: audience,
scope: scopes?.isNotEmpty == true
? scopes?.join(' ')
: null),
parameters)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class ClientOptions {
/// Note: The openid scope is always applied regardless of this setting.
final Set<String>? scopes;

/// The default additional parameters to be sent to Auth0.
final Map<String, String> parameters;

ClientOptions(
{required this.account,
this.authorizeTimeoutInSeconds,
Expand All @@ -119,5 +122,6 @@ class ClientOptions {
this.useRefreshTokensFallback,
this.idTokenValidationConfig,
this.audience,
this.scopes});
this.scopes,
this.parameters = const {}});
}

0 comments on commit 8a7aa05

Please sign in to comment.