Fresh<T> class

A Dio Interceptor for automatic token refresh. Requires a concrete implementation of TokenStorage and RefreshToken. Handles transparently refreshing/caching tokens.

dio.interceptors.add(
  Fresh<OAuth2Token>(
    tokenStorage: InMemoryTokenStorage(),
    refreshToken: (token, client) async {...},
  ),
);
Mixed in types

Constructors

Fresh({required TokenHeaderBuilder<T> tokenHeader, required TokenStorage<T> tokenStorage, required RefreshToken<T> refreshToken, ShouldRefresh? shouldRefresh, Dio? httpClient})
A Dio Interceptor for automatic token refresh. Requires a concrete implementation of TokenStorage and RefreshToken. Handles transparently refreshing/caching tokens.

Properties

authenticationStatus Stream<AuthenticationStatus>
Returns a Stream<AuthenticationStatus> which can be used to get notified of changes to the authentication state based on the presence/absence of a token.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token Future<T?>
Returns the current token.
no setterinherited
tokenStorage TokenStorage<T>
Setter for the TokenStorage instance.
no getterinherited

Methods

clearToken() Future<void>
Clears token storage and updates the AuthenticationStatus to AuthenticationStatus.unauthenticated.
inherited
close() Future<void>
Closes Fresh StreamController.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(DioException err, ErrorInterceptorHandler handler) Future
Called when an exception was occurred during the request.
onRequest(RequestOptions options, RequestInterceptorHandler handler) Future
Called when the request is about to be sent.
onResponse(Response response, ResponseInterceptorHandler handler) Future
Called when the response is about to be resolved.
revokeToken() Future<void>
Delete the storaged token. and emit the AuthenticationStatus.unauthenticated if authenticationStatus not is AuthenticationStatus.unauthenticated This method should be called when the token is no longer valid.
inherited
setToken(T? token) Future<void>
Sets the internal token to the provided token and updates the AuthenticationStatus accordingly.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

oAuth2({required TokenStorage<OAuth2Token> tokenStorage, required RefreshToken<OAuth2Token> refreshToken, ShouldRefresh? shouldRefresh, Dio? httpClient, TokenHeaderBuilder<OAuth2Token>? tokenHeader}) Fresh<OAuth2Token>
A constructor that returns a Fresh interceptor that uses an OAuth2Token token.