Search in sources :

Example 1 with AuthenticationStateHandlerAdapter

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());
            });
        }
    });
}
Also used : RequestCallback(com.okta.oidc.RequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) AuthenticationException(com.okta.authn.sdk.AuthenticationException) NonNull(androidx.annotation.NonNull) AuthenticationStateHandlerAdapter(com.okta.authn.sdk.AuthenticationStateHandlerAdapter) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) Result(com.okta.oidc.results.Result)

Aggregations

NonNull (androidx.annotation.NonNull)1 AuthenticationException (com.okta.authn.sdk.AuthenticationException)1 AuthenticationStateHandlerAdapter (com.okta.authn.sdk.AuthenticationStateHandlerAdapter)1 AuthenticationResponse (com.okta.authn.sdk.resource.AuthenticationResponse)1 RequestCallback (com.okta.oidc.RequestCallback)1 Result (com.okta.oidc.results.Result)1 AuthorizationException (com.okta.oidc.util.AuthorizationException)1