Package com.tapkey.mobile.auth
Interface TokenRefreshHandler
-
public interface TokenRefreshHandler
Handles refreshing of authentication information. Needs to be implemented by the user of the SDK and passed to the Tapkey service factory builder prior to logging in the first users.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
refreshAuthenticationAsync
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. In case of a non-recoverable situation where the given user's access token cannot be renewed, the implementation must return aTkException
withAuthenticationHandlerErrorCodes.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, aTkException
with error codeAuthenticationHandlerErrorCodes.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 viaUserManager.updateAccessToken(String, String)
. If the error is temporary, like a lack of internet connectivity, a different exception shall be raised.- Parameters:
userId
- the ID of the user whose access token needs to be renewed.cancellationToken
- can be used to get notified on cancel events.- Returns:
- the new access token.
-
onRefreshFailed
void onRefreshFailed(String userId)
Will be called in case reauthentication of an access token has failed in a non-recoverable way. The SDK won't make any attempts to re-authenticate and won't make any calls on behalf of the given user until a new access token is set explicitly viaUserManager.updateAccessToken(String, String)
.- Parameters:
userId
- the ID of the user whose access token could not be renewed.
-
-