verifyIdToken static method
Implementation
static Future<Map<String, dynamic>> verifyIdToken(
String idToken, {
required String? clientId,
}) async {
// Your existing Google token verification logic
final uri = Uri.https('oauth2.googleapis.com', '/tokeninfo', {
'id_token': idToken,
});
final client = HttpClient();
final req = await client.getUrl(uri);
final resp = await req.close();
if (resp.statusCode != 200) {
throw AuthException('Invalid Google ID token');
}
final body = await resp.transform(utf8.decoder).join();
client.close();
final profile = json.decode(body) as Map<String, dynamic>;
// Verify audience
if (clientId != null && profile['aud'] != clientId) {
throw AuthException('Invalid token audience');
}
return profile;
}