AuthTokenModel class

OAuth2 authentication tokens for API access.

Contains both access and refresh tokens with their expiration times, following the OAuth2 token response format used by the My Fuel Orders backend.

Expiration times are stored as milliseconds since epoch. A 5-minute buffer is applied to expiration checks to trigger token refresh before the actual expiry, preventing race conditions between validation and the outgoing API call.

Use empty as a sentinel value and isEmpty / isNotEmpty to test for it. Two instances are equal when all fields match (via Equatable).

final token = AuthTokenModel.tryFromJson(responseJson, convert: true);
if (token != null && !token.isTokenExpired) {
  // Use token for authenticated requests.
}

See also:

Inheritance

Constructors

AuthTokenModel({required String accessToken, required String refreshToken, required String tokenType, required int expiresIn, required int refreshExpiresIn})
Creates an AuthTokenModel with all fields required.
const

Properties

accessToken String
The JWT access token included in the Authorization: Bearer header of protected API requests.
final
expiresIn int
The access token expiration time in milliseconds since epoch.
final
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether this instance represents the absent-token sentinel.
no setter
isNotEmpty bool
Whether this instance contains real token data.
no setter
isRefreshTokenExpired bool
Whether the refresh token has expired or is within 5 minutes of expiry.
no setter
isTokenExpired bool
Whether the access token has expired or is within 5 minutes of expiry.
no setter
props List<Object>
Fields used for value-based equality and hash code computation.
no setteroverride
refreshExpiresIn int
The refresh token expiration time in milliseconds since epoch.
final
refreshToken String
The JWT refresh token used to obtain a new access token without re-authentication.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
tokenType String
The OAuth2 token type, typically "Bearer".
final

Methods

copyWith({String? accessToken, String? refreshToken, String? tokenType, int? expiresIn, int? refreshExpiresIn}) AuthTokenModel
Creates a copy of this token with the given fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
A JSON map representation of this token suitable for SecureStorage persistence.
toString() String
A string representation of this object.
override

Operators

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

Static Methods

tryFromJson(Map<String, dynamic> json, {required bool convert}) AuthTokenModel?
Attempts to parse an AuthTokenModel from an OAuth2 token response map.

Constants

empty → const AuthTokenModel
A sentinel value representing the absence of valid tokens.
expiryBuffer → const Duration
Buffer applied to token expiry checks so tokens are refreshed proactively before the hard expiry deadline, preventing race conditions where a token expires between validation and the outgoing API call.