parseTokenResponse static method
Parses Google's OAuth2 token response.
Google returns a JSON object containing access_token and id_token
fields when the openid scope is requested. The id_token is preserved
in OAuth2PkceTokenResponse.raw for subsequent JWKS verification.
Implementation
static OAuth2PkceTokenResponse parseTokenResponse(
final Map<String, dynamic> responseBody,
) {
final error = responseBody['error'] as String?;
if (error != null) {
final description = responseBody['error_description'] as String?;
throw OAuth2InvalidResponseException(
'Google OAuth error: $error'
'${description != null ? ' - $description' : ''}',
);
}
final accessToken = responseBody['access_token'] as String?;
if (accessToken == null) {
throw const OAuth2MissingAccessTokenException(
'Missing access_token in Google token response',
);
}
return OAuth2PkceTokenResponse(accessToken: accessToken, raw: responseBody);
}