obtainAccessCredentialsViaUserConsent function

Future<AccessCredentials> obtainAccessCredentialsViaUserConsent(
  1. ClientId clientId,
  2. List<String> scopes,
  3. Client client,
  4. PromptUserForConsent userPrompt, {
  5. String? hostedDomain,
  6. int listenPort = 0,
  7. String? customPostAuthPage,
  8. AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
})

Obtain oauth2 AccessCredentials using the oauth2 authentication code flow.

The clientId that you obtain from the API Console Credentials page, as described in Obtain OAuth 2.0 credentials.

userPrompt will be used for directing the user/user-agent to a URI. See PromptUserForConsent for more information.

client will be used for making the HTTP requests needed to create the returned AccessCredentials.

If provided, restricts sign-in to Google Apps hosted accounts at hostedDomain. For more details, see https://developers.google.com/identity/protocols/oauth2/openid-connect#hd-param

The returned Future will complete with AccessCredentials if the user has given the application access to their data. Otherwise, a UserConsentException will be thrown.

The localhost port to use when listening for the redirect from a user browser interaction. Defaults to 0 - which means the port is dynamic.

Generally you want to specify an explicit port so you can configure it on the Google Cloud console.

{@macro googleapis_auth_custom_post_auth_page}

Implementation

Future<AccessCredentials> obtainAccessCredentialsViaUserConsent(
  ClientId clientId,
  List<String> scopes,
  Client client,
  PromptUserForConsent userPrompt, {
  String? hostedDomain,
  int listenPort = 0,
  String? customPostAuthPage,
  AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
}) =>
    AuthorizationCodeGrantServerFlow(
      authEndpoints,
      clientId,
      scopes,
      client,
      userPrompt,
      hostedDomain: hostedDomain,
      listenPort: listenPort,
      customPostAuthPage: customPostAuthPage,
    ).run();