AccessToken class
Represents a parsed and validated access token (JWT) for API authentication.
AccessToken provides convenient access to JWT payload information and validation methods for checking token expiration and validity.
Usage
// Parse a token string
final token = AccessToken.parse(jwtString);
// Check validity
if (token.isValid) {
print('Token is valid for user: ${token.userId}');
}
// Safe parsing
final result = AccessToken.tryParse(tokenString);
if (result.data != null) {
print('Token parsed successfully');
} else {
print('Parse error: ${result.error}');
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isExpired → bool
-
Checks if the token is expired.
no setter
- isValid → bool
-
Checks if the token is valid (not expired).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- userId → int?
-
The user ID extracted from the token payload, if present.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Returns the raw token string.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
parse(
String token) → AccessToken - Parses a JWT access token string.
-
tryParse(
String token) → ({AccessToken? data, Object? error}) - Tries to parse a JWT access token string, returning error info if invalid.