Skip to content

Commit

Permalink
fix: allow audience and scope to be supplied during initialization (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehobbsdev authored Jun 6, 2023
1 parent 4a053ad commit 9f7ddf2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
13 changes: 11 additions & 2 deletions auth0_flutter/lib/auth0_flutter_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Auth0Web {
/// learn more about these parameters.
/// * See the [ClientOptions] type for the full description of the remaining
/// parameters for this method.
/// * [audience] relates to the API Identifier you want to reference in your
/// access tokens. See [API settings](https://auth0.com/docs/get-started/apis/api-settings)
/// to learn more.
/// * [scopes] defaults to `openid profile email`. You can override these
/// scopes, but `openid` is always requested regardless of this setting.
Future<Credentials?> onLoad(
{final int? authorizeTimeoutInSeconds,
final CacheLocation? cacheLocation,
Expand All @@ -44,7 +49,9 @@ class Auth0Web {
final bool? useCookiesForTransactions,
final bool? useFormData,
final bool? useRefreshTokens,
final bool? useRefreshTokensFallback}) async {
final bool? useRefreshTokensFallback,
final String? audience,
final Set<String>? scopes}) async {
await Auth0FlutterWebPlatform.instance.initialize(
ClientOptions(
account: _account,
Expand All @@ -59,7 +66,9 @@ class Auth0Web {
useCookiesForTransactions: useCookiesForTransactions,
useFormData: useFormData,
useRefreshTokens: useRefreshTokens,
useRefreshTokensFallback: useRefreshTokensFallback),
useRefreshTokensFallback: useRefreshTokensFallback,
audience: audience,
scopes: scopes),
_userAgent);

if (await hasValidCredentials()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:auth0_flutter_platform_interface/auth0_flutter_platform_interface.dart';
import '../js_interop.dart';
import '../js_interop_utils.dart';

extension ClientOptionsExtension on ClientOptions {
Auth0ClientOptions toAuth0ClientOptions(final UserAgent userAgent) =>
Expand All @@ -19,5 +20,8 @@ extension ClientOptionsExtension on ClientOptions {
useCookiesForTransactions: useCookiesForTransactions,
useFormData: useFormData,
useRefreshTokens: useRefreshTokens,
useRefreshTokensFallback: useRefreshTokensFallback);
useRefreshTokensFallback: useRefreshTokensFallback,
authorizationParams: JsInteropUtils.stripNulls(AuthorizationParams(
audience: audience,
scope: scopes?.isNotEmpty == true ? scopes?.join(' ') : null)));
}
3 changes: 2 additions & 1 deletion auth0_flutter/lib/src/web/js_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class Auth0ClientOptions {
final bool? useCookiesForTransactions,
final bool? useFormData,
final bool? useRefreshTokens,
final bool? useRefreshTokensFallback});
final bool? useRefreshTokensFallback,
final AuthorizationParams? authorizationParams});
}

@JS()
Expand Down
14 changes: 13 additions & 1 deletion auth0_flutter_platform_interface/lib/src/web/client_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ class ClientOptions {
/// The configuration for validating ID tokens.
final IdTokenValidationConfig? idTokenValidationConfig;

/// The default audience to be used for requesting API access.
final String? audience;

/// The default scopes to be used on authentication requests.
///
/// This defaults to `openid profile email` if not specified.
///
/// Note: The openid scope is always applied regardless of this setting.
final Set<String>? scopes;

ClientOptions(
{required this.account,
this.authorizeTimeoutInSeconds,
Expand All @@ -107,5 +117,7 @@ class ClientOptions {
this.useFormData,
this.useRefreshTokens,
this.useRefreshTokensFallback,
this.idTokenValidationConfig});
this.idTokenValidationConfig,
this.audience,
this.scopes});
}

0 comments on commit 9f7ddf2

Please sign in to comment.