JwtExpress class

An immutable set of claims for a Java Web Token (JWT).

A claim is represented as a name/value pair, consisting of a Claim Name (which uniquely identifies the claim) and a Claim Value.

This implementation classifies claims into two types: "registered claims" correspond to the seven Registered Claim Names defined in section 4.1 of RFC 7519; and all other claims are "non-registered claims".

Registered claims have their own member variable (e.g. issuer, subject and audience).

Non-registered claims are accessed through the list access operator[] and their presence can be determined using the containsKey method.

The Claim Names of all present claims can be obtained using claimNames.

Issue token from JwtExpress:

    final claimSet = JwtExpress(
      subject: 'kleak',
      issuer: 'teja',
      audience: <String>['example.com', 'client2.example.com'],
      otherClaims: <String, dynamic>{ 'pld': {'k': 'v'} });

    final token = issueExpressToken(claimSet, key);
    print(token);

Parse JwtExpress from token:

    final decClaimSet = verifyJwtHS256Signature(token, key);
    print(decClaimSet);

Constructors

JwtExpress({String? issuer, String? subject, List<String>? audience, DateTime? expiry, DateTime? notBefore, DateTime? issuedAt, String? jwtId, Map<String, dynamic>? otherClaims, Map<String, dynamic>? payload, bool defaultIatExp = true, Duration? maxAge})
Registered claims are populated with these parameters:
JwtExpress.fromMap(Map data, {bool defaultIatExp = true, Duration? maxAge})
Constructs a claim set from a Map of claims.
factory

Properties

audience List<String>?
Audience Claim
final
expiry DateTime?
Expiration Time Claim
final
hashCode int
The hash code for this object.
no setterinherited
issuedAt DateTime?
Issued At Claim
final
issuer String?
Issuer Claim
final
jwtId String?
JWT ID Claim
final
notBefore DateTime?
Not Before Claim
final
payload Map<String, dynamic>
The payload (pld) claim.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
subject String?
Subject Claim
final

Methods

claimNames({bool includeRegisteredClaims = true}) Iterable<String>
Returns an Iterable of all the Claim Names of claims in the claim set.
containsKey(String claimName) bool
Indicates if a claim exists or not.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts the claim set into a Map suitable for encoding as JSON.
toString() String
Converts a JwtExpress into a multi-line String for display.
override
validate({String? issuer, String? audience, Duration? allowedClockSkew, DateTime? currentTime}) → void
Validates the JWT claim set.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String claimName) → dynamic
Retrieves the value of a claim.

Constants

defaultMaxAge → const Duration
Default duration between issued time and expiry time.
registeredClaimNames → const List<String>
Claim Names for all the Registered Claim Names.