Logging out
Introduction
In the SDK a user is treated as logged in as long as the user has an access token for the operation to be executed. To logout the user the access token should be removed. This can be done by calling the logout function on the UserClient. The SDK will also send a request to the Token Server to remove the access token to ensure the token is invalidated both on the client as server side. If a refresh token is stored on the device, it will remain after the logout action, so it can be used to login again later.
Example code
Example code to logout a user:
Handler methods
void onSuccess()
is called when the logout was successful, so you should redirect user to a login screen.- If
void onError(final OneginiLogoutError oneginiLogoutError)
was called, it indicates that some error during logout occurred. For example: the SDK was able to remove the access token from storage, but revoke request that was send to the Token Server failed for some reason. In such scenerio you should still redirect user to login screen.
Please note that you can handle errors that are relevant to you differently. To accomplish that you should compare the OneginiLogoutError#getErrorType()
value
with the OneginiLogoutError
error type definitions. The OneginiLogoutError
will also contain an additional error description for debugging and possibly a
Throwable
object which you can get with the getMessage()
and getCause()
methods.
For more info on error handling see the Error handling topic guide.