idToken method
An unsigned ID token with the usual Google claims, as
signInWithGoogle returns it here. Never accept such a token on a
server.
Implementation
String idToken({
String? nonce,
Duration validFor = const Duration(hours: 1),
}) {
String part(Object json) =>
base64Url.encode(utf8.encode(jsonEncode(json))).replaceAll('=', '');
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final payload = {
'iss': 'https://accounts.google.com',
'aud': 'fake-client-id.apps.googleusercontent.com',
'sub': 'fake-${googleEmail.hashCode.abs()}',
'email': googleEmail,
'email_verified': true,
'name': ?googleName,
'iat': now,
'exp': now + validFor.inSeconds,
'nonce': ?nonce,
'jti': '${++_ids}', // each token differs, like real ones
};
return '${part({'alg': 'none', 'typ': 'JWT'})}.${part(payload)}'
'.fake-signature';
}