getAccessToken method
Builds JWT and exchanges it with service account access token
Implementation
Future<String> getAccessToken() async {
final jwt = _createJWT();
final apiResult = await _httpClient.post<_GoogleCloudAuthResponse>(
path: 'token',
decoder: (response) => _GoogleCloudAuthResponse.fromJson(
jsonDecode(response.body),
),
body: {
'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion': jwt,
});
if (!apiResult.succeeded) {
logger.error('Failed to get Google Cloud token', apiResult.error!);
throw apiResult.error!;
}
return apiResult.valueUnsafe.accessToken;
}