load method
Parses a JWT token, validating it, and returns a JwtPayload representing its contents.
Implementation
JwtPayload load(String token) {
if (token.startsWith('Bearer ')) {
token = token.substring('Bearer '.length);
}
var parts = token.split('.');
if (parts.length != 3) {
throw InvalidTokenException(reason: 'Token should have 3 sections.');
}
var headerBase64 = parts[0];
var payloadBase64 = parts[1];
var checkSignature = _sign(headerBase64, payloadBase64);
var signature = parts[2];
if (checkSignature != signature) {
throw InvalidSignatureException();
}
var payload = _deserializePayload(payloadBase64);
return payload;
}