clientViaUserConsent method
Obtains AccessCredentials and returns an authenticated HTTP client.
HTTP requests made on the returned client will get an additional
Authorization
header with the AccessCredentials obtained.
Once the AccessCredentials expire, it will use it's refresh token
(if available) to obtain new credentials.
See autoRefreshingClient for more information.
See obtainAccessCredentialsViaUserConsent for how credentials will be
obtained. Errors from obtainAccessCredentialsViaUserConsent will be let
through to the returned Future
of this function and to the returned
HTTP client (in case of credential refreshes).
The returned HTTP client will forward errors from lower levels via it's
Future<Response>
or it's Response.read()
stream.
If immediate
is true
there will be no user involvement. If the user
is either not logged in or has not already granted the application access,
a UserConsentException
will be thrown.
If immediate
is false
the user might be asked to login (if not
already logged in) and might get asked to grant the application access
(if the application hasn't been granted access before).
The user is responsible for closing the returned HTTP Client
.
If loginHint
is not null
, it will be passed to the server as a hint
to which user is being signed-in. This can e.g. be an email or a User ID
which might be used as pre-selection in the sign-in flow.
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
Implementation
Future<AutoRefreshingAuthClient> clientViaUserConsent({
bool immediate = false,
String? loginHint,
String? hostedDomain,
}) async {
final credentials = await obtainAccessCredentialsViaUserConsent(
immediate: immediate,
loginHint: loginHint,
hostedDomain: hostedDomain,
);
return _clientFromCredentials(credentials);
}