autoRefreshingClient function
AutoRefreshingAuthClient
autoRefreshingClient(
- ClientId clientId,
- AccessCredentials credentials,
- Client baseClient, {
- AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
Creates an AutoRefreshingAuthClient which automatically refreshes
credentials
before they expire.
The clientId
that you obtain from the API Console
Credentials page,
as described in
Obtain OAuth 2.0 credentials.
Uses baseClient
to make authenticated HTTP requests and to refresh
credentials
.
The user is responsible for closing the returned HTTP Client
.
Closing the returned Client
will not close baseClient
.
Implementation
AutoRefreshingAuthClient autoRefreshingClient(
ClientId clientId,
AccessCredentials credentials,
Client baseClient, {
AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
}) {
if (credentials.accessToken.type != 'Bearer') {
throw ArgumentError('Only Bearer access tokens are accepted.');
}
if (credentials.refreshToken == null) {
throw ArgumentError('Refresh token in AccessCredentials was `null`.');
}
return AutoRefreshingClient(baseClient, authEndpoints, clientId, credentials);
}