getAuthToken method

Future<GetAuthTokenResult> getAuthToken(
  1. TokenDetails? details
)

Gets an OAuth2 access token using the client ID and scopes specified in the oauth2 section of manifest.json.

The Identity API caches access tokens in memory, so it's ok to call getAuthToken non-interactively any time a token is required. The token cache automatically handles expiration.

For a good user experience it is important interactive token requests are initiated by UI in your app explaining what the authorization is for. Failing to do this will cause your users to get authorization requests, or Chrome sign in screens if they are not signed in, with with no context. In particular, do not use getAuthToken interactively when your app is first launched.

Note: When called with a callback, instead of returning an object this function will return the two properties as separate arguments passed to the callback.

|details| : Token options. |callback| : Called with an OAuth2 access token as specified by the manifest, or undefined if there was an error. The grantedScopes parameter is populated since Chrome 87. When available, this parameter contains the list of granted scopes corresponding with the returned token.

Implementation

Future<GetAuthTokenResult> getAuthToken(TokenDetails? details) async {
  var $res = await promiseToFuture<$js.GetAuthTokenResult>(
      $js.chrome.identity.getAuthToken(details?.toJS));
  return GetAuthTokenResult.fromJS($res);
}