use of com.okta.authn.sdk.AuthenticationStateHandlerAdapter in project okta-oidc-android by okta.
the class SampleActivity method onSignIn.
@Override
public void onSignIn(String username, String password) {
mSignInDialog.dismiss();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
mTvStatus.setText("Invalid username or password");
return;
}
showNetworkProgress(true);
mExecutor.submit(() -> {
try {
if (mAuthenticationClient == null) {
return;
}
mAuthenticationClient.authenticate(username, password.toCharArray(), null, new AuthenticationStateHandlerAdapter() {
@Override
public void handleUnknown(AuthenticationResponse authenticationResponse) {
SampleActivity.this.runOnUiThread(() -> {
showNetworkProgress(false);
mTvStatus.setText(authenticationResponse.getStatus().name());
});
}
@Override
public void handleLockedOut(AuthenticationResponse lockedOut) {
SampleActivity.this.runOnUiThread(() -> {
showNetworkProgress(false);
mTvStatus.setText("Account locked out");
});
}
@Override
public void handleSuccess(AuthenticationResponse successResponse) {
String sessionToken = successResponse.getSessionToken();
mAuthClient.signIn(sessionToken, mPayload, new RequestCallback<Result, AuthorizationException>() {
@Override
public void onSuccess(@NonNull Result result) {
mTvStatus.setText("authentication authorized");
mIsSessionSignIn = true;
showAuthenticatedMode();
showNetworkProgress(false);
}
@Override
public void onError(String error, AuthorizationException exception) {
mTvStatus.setText(error);
}
});
}
});
} catch (AuthenticationException e) {
Log.e(TAG, Log.getStackTraceString(e));
runOnUiThread(() -> {
showNetworkProgress(false);
mTvStatus.setText(e.getMessage());
});
}
});
}
Aggregations