TokenProvider class abstract

Interface for providing authentication tokens.

Implement this interface to integrate your token storage with apix. All methods are async for compatibility with secure storage solutions.

Example:

class MyTokenProvider implements TokenProvider {
  final FlutterSecureStorage _storage;

  MyTokenProvider(this._storage);

  @override
  Future<String?> getAccessToken() => _storage.read(key: 'access_token');

  @override
  Future<String?> getRefreshToken() => _storage.read(key: 'refresh_token');

  @override
  Future<void> saveTokens(String accessToken, String refreshToken) async {
    await _storage.write(key: 'access_token', value: accessToken);
    await _storage.write(key: 'refresh_token', value: refreshToken);
  }

  @override
  Future<void> clearTokens() async {
    await _storage.delete(key: 'access_token');
    await _storage.delete(key: 'refresh_token');
  }
}
Implementers

Constructors

TokenProvider()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearTokens() Future<void>
Clears all tokens (e.g., on logout).
getAccessToken() Future<String?>
Returns the current access token, or null if not available.
getRefreshToken() Future<String?>
Returns the current refresh token, or null if not available.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
saveTokens(String accessToken, String refreshToken) Future<void>
Saves both tokens after a successful authentication or refresh.
toString() String
A string representation of this object.
inherited

Operators

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