idToken property
The Map<String, dynamic>
representation of the received ID Token.
This getter converts the received idTokenRaw
to a dictionary format if it exists.
If you are not applying an ID Token when login, null
is returned.
Implementation
Map<String, dynamic>? get idToken {
// Lazy variable.
if (_idToken != null) {
return _idToken;
}
if (idTokenRaw == null) {
return null;
}
final parts = idTokenRaw!.split('.');
// Malformed JWT format.
if (parts.length != 3) {
return null;
}
// dart:convert is a bit pedantic and it requires a normalized format of base 64,
// even encoded by base 64 url.
// https://github.com/dart-lang/sdk/issues/39510
final normalizedPayload = base64.normalize(parts[1]);
final jsonPayload = utf8.decode(base64Url.decode(normalizedPayload));
_idToken = jsonDecode(jsonPayload);
return _idToken;
}