FreshGrpc<T> class
A Grpc Authenticator for automatic token refresh. Requires a concrete implementation of TokenStorage, ObtainToken and RefreshToken. Handles transparently refreshing/caching tokens.
- Mixed in types
-
- FreshMixin<
T>
- FreshMixin<
Constructors
-
FreshGrpc({required TokenStorage<
T> tokenStorage, required ObtainToken<T> obtainToken, required RefreshToken<T> refreshToken, ShouldRefresh<T> ? shouldRefresh, TokenHeaderBuilder<T> ? tokenHeader, RetryOptions retryOptions = const RetryOptions(delayFactor: Duration(milliseconds: 200), randomizationFactor: 0.25, maxDelay: Duration(seconds: 5), maxAttempts: 3)})
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
- toCallOptions → CallOptions
-
no setterinherited
-
token
→ Future<
T?> -
Returns the current token.
no setterinherited
-
tokenStorage
← TokenStorage<
T> -
Setter for the TokenStorage instance.
no getterinherited
Methods
-
authenticate(
Map< String, String> metadata, String uri) → Future<void> -
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
-
obtainAccessCredentials(
String uri) → Future< void> -
retryUnary<
R, Q> (ResponseFuture< R> rpc(Q request, {CallOptions? options}), Q request, {dynamic onRetry(Exception)?, CallOptions? options}) → Future<R> -
Call
rpc
retrying so long as_shouldRefresh
returntrue
for the exception thrown. -
revokeToken(
) → Future< void> -
Delete the storaged token. and emit the
AuthenticationStatus.unauthenticated
if authenticationStatus not isAuthenticationStatus.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 providedtoken
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 ObtainToken<OAuth2Token> obtainToken, required RefreshToken<OAuth2Token> refreshToken, ShouldRefresh<OAuth2Token> ? shouldRefresh, TokenHeaderBuilder<OAuth2Token> ? tokenHeader}) → FreshGrpc<OAuth2Token>