public interface TokenRefreshHandler
Modifier and Type | Method and Description |
---|---|
void |
onRefreshFailed(String userId)
Will be called in case reauthentication of an access token has failed in a non-recoverable
way.
|
Promise<String> |
refreshAuthenticationAsync(String userId,
CancellationToken cancellationToken)
Will be called by the SDK whenever the Tapkey access token of the given user needs to be
refreshed.
|
Promise<String> refreshAuthenticationAsync(String userId, CancellationToken cancellationToken)
TkException
with
AuthenticationHandlerErrorCodes.TokenRefreshFailed
.
An exemplary implementation may look similar to:
@Override Promise<String> refreshAuthenticationAsync(String userId, CancellationToken cancellationToken) { try { // Custom application logic to retrieve a new access token return getNewAccessToken(userId, cancellationToken); } catch (Exception e) { if (isPersistentError(e)) { throw new TkException(AuthenticationHandlerErrorCodes.TokenRefreshFailed); } else { throw e; } } }In case getNewAccessToken() from the snippet above throws, the implementor shall check the type of error that occurred. If it is a persistent error that cannot be recovered, like if the refresh token got invalid, a
TkException
with error code
AuthenticationHandlerErrorCodes.TokenRefreshFailed
shall be raised. Subsequently,
onRefreshFailed(String)
is invoked and the SDK won't request to refresh the access
token or make any calls on behalf of the given user until a new token is set explicitly via
UserManager.updateAccessToken(String, String)
.
If the error is temporary, like a lack of internet connectivity, a different exception shall
be raised.userId
- the ID of the user whose access token needs to be renewed.cancellationToken
- can be used to get notified on cancel events.void onRefreshFailed(String userId)
UserManager.updateAccessToken(String, String)
.userId
- the ID of the user whose access token could not be renewed.