Last updated:
0 purchases
jsonwebtoken decode
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')}'),
copied to clipboard
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}'),
copied to clipboard
Create your own PayloadClaims class #
class MyClaims extends PayloadClaims {
MyClaims(super.jwtBuilder);
get myPublicClaim => claim('my_public_claim');
}
copied to clipboard
See more: example;
Created following iana guidelines: https://www.iana.org/assignments/jwt/jwt.xhtml;
Sample token from jwt official website: https://jwt.io/;
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.