Deregister users
Deregistering users implies removing of all of their data (including access tokens and refresh tokens) from the device. Client credentials remain stored on the device.
To call UserClient#deregisterUser
you require the following two arguments:
-
UserProfile
is the object describing which user you want to deregister. -
OneginiDeregisterUserProfileHandler
is the handler that indicates the result.
Example: deleting a currently authenticated user
In this example, if void onSuccess
is called, the user was successfully deleted and the user should be redirected to the login screen. void onError(final OneginiDeregistrationError oneginiDeregistrationError)
is called if an error occurred during the operation.
@OnClick(R.id.button_deregister_user)
public void deregisterUser() {
final OneginiClient oneginiClient = OneginiSDK.getOneginiClient(this);
final UserProfile userProfile = oneginiClient.getUserClient().getAuthenticatedUserProfile();
if (userProfile == null) {
showToast("userProfile == null");
return;
}
new DeregistrationUtil(this).onUserDeregistered(userProfile);
oneginiClient.getUserClient().deregisterUser(userProfile, new OneginiDeregisterUserProfileHandler() {
@Override
public void onSuccess() {
onUserDeregistered();
}
@Override
public void onError(final OneginiDeregistrationError oneginiDeregistrationError) {
onUserDeregistrationError(oneginiDeregistrationError);
}
}
);
}
private void onUserDeregistered() {
showToast("deregisterUserSuccess");
startLoginActivity();
}
private void onUserDeregistrationError(final OneginiDeregistrationError oneginiDeregistrationError) {
@OneginiDeregistrationError.DeregistrationErrorType final int errorType = oneginiDeregistrationError.getErrorType();
if (errorType == OneginiDeregistrationError.DEVICE_DEREGISTERED) {
// Deregistration failed due to missing device credentials. Register app once again.
new DeregistrationUtil(this).onDeviceDeregistered();
}
// other errors don't really require our reaction, but you might consider displaying some message to the user
showToast("Deregistration error: " + oneginiDeregistrationError.getMessage());
startLoginActivity();
}
Any existing user can be deregistered.
Handler methods
-
When
void onSuccess
is called, then it's clear that the user was successfully deregistered, so you should redirect the user to a login screen. -
The method
void onError(final OneginiDeregistrationError oneginiDeregistrationError)
is called when some error happened during the action. For example theUserProfile
was deleted from the device, but the request to the server failed. In such a situation, you would still want to redirect the user to the login screen, but you can also perform some additional action such as notifying.
You can handle errors that are relevant to you differently. To accomplish that, you should compare the OneginiDeregistrationError#getErrorType()
value with the OneginiDeregistrationError
error type definitions. The OneginiDeregistrationError
will also contain an additional error description for debugging and possibly a Throwable
object that you can get with the getMessage()
and getCause()
methods.