TKMTokenRefreshHandler
public protocol TKMTokenRefreshHandler
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.
-
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 a
TKMException
withTKMAuthenticationHandlerErrorCodes.TokenRefreshFailed
.An exemplary implementation may look similar to:
func refreshAuthenticationAsync(userId: String, cancellationToken: TKMCancellationToken) -> TKMPromise<String> { do { // Custom application logic to retrieve a new access token return try getNewAccessToken(userId, cancellationToken) } catch (e) { return TKMAsync.promiseFromError(TKMError(errorDescriptor: TKMErrorDescriptor( code: TKMAuthenticationHandlerErrorCodes.TokenRefreshFailed, message: "No new token can be obtained.", details: e))) } }
In case getNewAccessToken() from the snippet above throws, the SDK is notified that there is no way to renew the access token for the given user at this time. Subsequently,
onRefreshFailed(userId:)
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 viaTKMUserManager.updateAccessToken(userId:accessToken:)
.Declaration
Swift
func refreshAuthenticationAsync(userId: String, cancellationToken: TKMCancellationToken) -> TKMPromise<String>
Parameters
userId
the ID of the user whose access token needs to be renewed.
cancellationToken
can be used to get notified on cancel events.
Return Value
the new access token.
-
Will be called in case re-authentication 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 via
TKMUserManager.updateAccessToken(userId:accessToken:)
.Declaration
Swift
func onRefreshFailed(userId: String)
Parameters
userId
the ID of the user whose access token could not be renewed.