getApiCredentials method

Future<ApiCredentials> getApiCredentials({
  1. required String audience,
  2. Set<String> scopes = const {},
  3. Map<String, String> parameters = const {},
})

Retrieves a set of ApiCredentials scoped to a specific API (audience) by reusing the stored refresh token via Multi-Resource Refresh Tokens (MRRT).

Enable MRRT by passing useMrrt: true to onLoad. This exchanges the single refresh token obtained at login for an access token valid for the requested audience, without requiring the user to log in again.

Additional notes:

  • scopes are the scopes to request for the new access token. If empty, the default scopes configured for the API are used.
  • Arbitrary parameters can be specified and then picked up in a custom Auth0 Action.

Prerequisites:

  • MRRT must be enabled on your Auth0 tenant.
  • The user must have logged in with the offline_access scope so that a refresh token is available for the exchange.

Throws a WebException if the exchange fails.

Implementation

Future<ApiCredentials> getApiCredentials({
  required final String audience,
  final Set<String> scopes = const {},
  final Map<String, String> parameters = const {},
}) =>
    Auth0FlutterWebPlatform.instance.getApiCredentials(
      GetApiCredentialsOptions(
        audience: audience,
        scopes: scopes,
        parameters: parameters,
      ),
    );