Logout a user¶
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 to logout a user:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
void onSuccess()is called when the logout was successful, so you should redirect user to a login screen.
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 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
For more info on error handling see the error handling topic guide.