TomServerJwtToken class

Server-side JWT token generator.

TomServerJwtToken creates signed JWT tokens with both public and encrypted payload sections. Use this class on the server to generate tokens for client authentication.

Token Structure

The generated token contains:

  • Public claims: Visible to anyone who can decode the token
  • Encrypted claims: RSA-encrypted, only readable with the private key
  • validUntil: Expiration timestamp
  • validFrom: Start of validity window

Usage

final token = TomServerJwtToken(
  {'userId': '123', 'role': 'user'},
  encryptedData: {'sessionSecret': 'abc123'},
  expiresIn: Duration(hours: 24),
);

final jwtString = token.getJWT('my-issuer');
// Send jwtString to the client

Constructors

TomServerJwtToken(Map<String, Object?> publicData, {Map<String, Object?> encryptedData = const {}, Duration expiresIn = const Duration(hours: 2), Duration notBefore = const Duration(seconds: 0), bool noIssueAt = false, String? audience, TomJwtConfiguration? signingConfiguration})
Creates a new server-side JWT token.

Properties

audience ↔ String?
The aud claim: the service this token is meant for, or null for none.
getter/setter pair
encryptedData ↔ Map<String, Object?>
Sensitive data that will be RSA-encrypted in the token.
getter/setter pair
expiresIn ↔ Duration
How long until the token expires.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
noIssueAt ↔ bool
Whether to omit the "issued at" claim.
getter/setter pair
notBefore ↔ Duration
Delay before the token becomes valid.
getter/setter pair
publicData ↔ Map<String, Object?>
Public claims visible in the token payload.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
signingConfiguration ↔ TomJwtConfiguration
The signing configuration to use for this token.
getter/setter pair

Methods

getJWT(String issuer) → String
Generates and signs the JWT token string.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited