clientViaUserConsentManual function
Future<AutoRefreshingAuthClient>
clientViaUserConsentManual(
- ClientId clientId,
- List<
String> scopes, - PromptUserForConsentManual userPrompt, {
- Client? baseClient,
- String? hostedDomain,
- AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
Obtains oauth2 credentials and returns an authenticated HTTP client.
See obtainAccessCredentialsViaUserConsentManual for specifics about the arguments used for obtaining access credentials.
The clientId
that you obtain from the API Console
Credentials page,
as described in
Obtain OAuth 2.0 credentials.
If baseClient
is provided, all HTTP requests will be made with it.
Otherwise, a new Client
instance will be created.
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 user is responsible for closing the returned HTTP Client
.
Closing the returned Client
will not close baseClient
.
Implementation
Future<AutoRefreshingAuthClient> clientViaUserConsentManual(
ClientId clientId,
List<String> scopes,
PromptUserForConsentManual userPrompt, {
Client? baseClient,
String? hostedDomain,
AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
}) async {
var closeUnderlyingClient = false;
if (baseClient == null) {
baseClient = Client();
closeUnderlyingClient = true;
}
final flow = AuthorizationCodeGrantManualFlow(
authEndpoints,
clientId,
scopes,
baseClient,
userPrompt,
hostedDomain: hostedDomain,
);
AccessCredentials credentials;
try {
credentials = await flow.run();
} catch (e) {
if (closeUnderlyingClient) {
baseClient.close();
}
rethrow;
}
return AutoRefreshingClient(
baseClient,
authEndpoints,
clientId,
credentials,
closeUnderlyingClient: closeUnderlyingClient,
);
}