Changing PIN
The UserClient offers a method to change the PIN for the currently logged in user profile. This methods is called changePin and requires one argument:
OneginiChangePinHandleris the changed PIN handler to return the result of change PIN action.
The Android SDK will handle flow of changing the PIN using OneginiPinAuthenticationRequestHandler and OneginiCreatePinRequestHandler handlers. See Authenticate user with PIN to learn how to implement those two handlers and how to cancel the PIN change process.
Handler methods
void onSuccess()is called when PIN was changed.void onError(final OneginiChangePinError oneginiChangePinError)is called when some error during changing PIN occurred.
Example: change the user PIN
As you can see in the example, we handle only one error case: when the user got deregistered (probably due to too many failure PIN attempts). You can handle errors that are relevant to you differently. To accomplish that you should compare the OneginiChangePinError#getErrorType() value with the OneginiChangePinError error type definitions. The OneginiChangePinError will also contain an additional error description for debugging and possibly a Throwable object that you can get with the getMessage() and getCause() methods.
public void startChangePinFlow() {
OneginiSDK.getOneginiClient(this).getUserClient().changePin(new OneginiChangePinHandler() {
@Override
public void onSuccess() {
showToast("Change PIN action finished successfully");
}
@Override
public void onError(final OneginiChangePinError oneginiChangePinError) {
@OneginiChangePinError.ChangePinErrorType int errorType = oneginiChangePinError.getErrorType();
if (errorType == OneginiChangePinError.USER_DEREGISTERED) {
userDeregistered();
} else if (errorType == OneginiChangePinError.DEVICE_DEREGISTERED) {
new DeregistrationUtil(SettingsActivity.this).onDeviceDeregistered();
}
showToast(oneginiChangePinError.getMessage());
}
});
}
private void userDeregistered() {
final Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
UserProfile authenticatedUserProfile = OneginiSDK.getOneginiClient(SettingsActivity.this).getUserClient().getAuthenticatedUserProfile();
if (authenticatedUserProfile == null) {
return;
}
new DeregistrationUtil(this).onUserDeregistered(authenticatedUserProfile);
}