jsonwebtoken_decode 1.1.2 copy "jsonwebtoken_decode: ^1.1.2" to clipboard
jsonwebtoken_decode: ^1.1.2 copied to clipboard

Package for decoding Json Web Token (JWT), and selecting specific claims.

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;

example

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/;

5
likes
130
pub points
69%
popularity

Publisher

unverified uploader

Package for decoding Json Web Token (JWT), and selecting specific claims.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on jsonwebtoken_decode