JSONWEBTOKEN DECODE
Package for decoding Json Web Token (JWT), and selecting specific claims.
Features
- Decode jwt;
- Get Header and Payload claims;
- Get OpenID claims;
- Get Keycloak claims;
- Get custom claims;
Usage
// ...
final String _token ='valid_token';
JwtBuilder? _jwtBuilder;
Payload? _payload;
Header? _header;
@override
void initState() {
super.initState();
_jwtBuilder = JwtBuilder.fromToken(_token);
_payload = _jwtBuilder!.payload;
_header = _jwtBuilder!.header;
}
// ...
Text('${_payload!.claim('name')}'),
Usage Claims
// ...
final String _token ='valid_token';
JwtBuilder? _jwtBuilder;
PayloadClaims? _payloadClaims;
OpenIdClaims? _openIdClaims;
KeycloakClaims? _keycloakClaims;
HeaderClaims? _headerClaims;
@override
void initState() {
super.initState();
_jwtBuilder = JwtBuilder.fromToken(_token);
_payloadClaims = PayloadClaims(_jwtBuilder!);
_openIdClaims = OpenIdClaims(_jwtBuilder!);
_keycloakClaims = KeycloakClaims(_jwtBuilder!);
_headerClaims = HeaderClaims(_jwtBuilder!);
}
// ...
Text('${_payloadClaims!.sub}'),
Text('${_openIdClaims!.name}'),
Text('${_keycloakClaims!.rolesRealmAccess}'),
Text('${_headerClaims!.typ}'),
Create your own PayloadClaims class
class MyClaims extends PayloadClaims {
MyClaims(super.jwtBuilder);
get myPublicClaim => claim('my_public_claim');
}
See more: example;
Created following iana guidelines: https://www.iana.org/assignments/jwt/jwt.xhtml;
Sample token from jwt official website: https://jwt.io/;
Libraries
- builder/jwt_builder
- builder/mixin/decode_to_map
- builder/parts/jwt_parts/header_part
- builder/parts/jwt_parts/payload_part
- builder/parts/part
- claims/claims
- claims/header_claims
- claims/keycloak_claims
- claims/openid_claims
- claims/payload_claims
- exception/data_extractor_token_exception
- jsonwebtoken_decode