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

6
likes
150
points
120
downloads

Publisher

unverified uploader

Weekly Downloads

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