onLoad method

Future<Credentials?> onLoad({
  1. int? authorizeTimeoutInSeconds,
  2. CacheLocation? cacheLocation,
  3. String? cookieDomain,
  4. int? httpTimeoutInSeconds,
  5. String? issuer,
  6. int? leeway,
  7. bool? useLegacySameSiteCookie,
  8. int? sessionCheckExpiryInDays,
  9. bool? useCookiesForTransactions,
  10. bool? useFormData,
  11. bool? useRefreshTokens,
  12. bool? useRefreshTokensFallback,
  13. bool? useMrrt,
  14. String? audience,
  15. Set<String>? scopes,
  16. Map<String, String> parameters = const {},
})

Initializes the client.

This should be called during the loading phase of your application. If the current user already has a session with Auth0, an instance of Credentials will be returned, populated with their user data and tokens.

Additional notes:

  • You can specify custom leeway and issuer values to be used for the validation of the ID token. See the IdTokenValidationConfig type to 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 to learn more.
  • scopes defaults to openid profile email. You can override these scopes, but openid is always requested regardless of this setting.
  • useMrrt enables Multi-Resource Refresh Tokens, allowing a single refresh token to be reused to obtain access tokens for multiple APIs (audiences). Once enabled, request per-audience tokens via getApiCredentials. Enabling this forces useRefreshTokens on (even if it was explicitly set to false), and requires MRRT to be enabled on your Auth0 tenant.

Implementation

Future<Credentials?> onLoad(
    {final int? authorizeTimeoutInSeconds,
    final CacheLocation? cacheLocation,
    final String? cookieDomain,
    final int? httpTimeoutInSeconds,
    final String? issuer,
    final int? leeway,
    final bool? useLegacySameSiteCookie,
    final int? sessionCheckExpiryInDays,
    final bool? useCookiesForTransactions,
    final bool? useFormData,
    final bool? useRefreshTokens,
    final bool? useRefreshTokensFallback,
    final bool? useMrrt,
    final String? audience,
    final Set<String>? scopes,
    final Map<String, String> parameters = const {}}) async {
  await Auth0FlutterWebPlatform.instance.initialize(
      ClientOptions(
          account: _account,
          useDPoP: _useDPoP,
          authorizeTimeoutInSeconds: authorizeTimeoutInSeconds,
          cacheLocation: cacheLocation ?? _cacheLocation,
          cookieDomain: cookieDomain,
          httpTimeoutInSeconds: httpTimeoutInSeconds,
          idTokenValidationConfig:
              IdTokenValidationConfig(issuer: issuer, leeway: leeway),
          useLegacySameSiteCookie: useLegacySameSiteCookie,
          sessionCheckExpiryInDays: sessionCheckExpiryInDays,
          useCookiesForTransactions: useCookiesForTransactions,
          useFormData: useFormData,
          useRefreshTokens: useRefreshTokens,
          useRefreshTokensFallback: useRefreshTokensFallback,
          useMrrt: useMrrt,
          audience: audience,
          scopes: scopes,
          parameters: {
            if (_redirectUrl != null) 'redirect_uri': _redirectUrl,
            ...parameters
          }),
      _userAgent);

  if (await hasValidCredentials()) {
    return credentials();
  }

  return null;
}