Search in sources :

Example 6 with Result

use of com.okta.oidc.results.Result in project okta-oidc-android by okta.

the class WebAuthClientImpl method signIn.

@Override
@AnyThread
public void signIn(@NonNull final Activity activity, AuthenticationPayload payload) {
    registerActivityLifeCycle(activity);
    cancelFuture();
    // add the login hint if it exists.
    if (payload == null && mLoginHint != null) {
        payload = new AuthenticationPayload.Builder().setLoginHint(mLoginHint).build();
    } else if (mLoginHint != null) {
        payload = new AuthenticationPayload.Builder().copyPayload(payload).setLoginHint(mLoginHint).build();
    }
    final AuthenticationPayload finalPayload = payload;
    mFutureTask = mDispatcher.submit(() -> {
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        try {
            Result result = mSyncAuthClient.signIn(activity, finalPayload);
            processSignInResult(result);
        } catch (InterruptedException e) {
            mDispatcher.submitResults(() -> {
                if (mResultCb != null) {
                    mResultCb.onCancel();
                }
            });
        }
    });
}
Also used : AuthenticationPayload(com.okta.oidc.AuthenticationPayload) Result(com.okta.oidc.results.Result) AnyThread(androidx.annotation.AnyThread)

Example 7 with Result

use of com.okta.oidc.results.Result 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)

Example 8 with Result

use of com.okta.oidc.results.Result in project okta-oidc-android by okta.

the class SyncWebAuthClientImpl method signOut.

@Override
public int signOut(@NonNull final Activity activity, int flags) {
    try {
        mSignOutStatus = SUCCESS;
        mSignOutFlags = flags;
        revokeTokens(getSessionClient());
        if ((flags & SIGN_OUT_SESSION) == SIGN_OUT_SESSION) {
            Result result = signOutOfOkta(activity);
            if (!result.isSuccess()) {
                Log.w(TAG, "Failed to clear session", result.getError());
                mSignOutStatus |= FAILED_CLEAR_SESSION;
            }
        }
        return mSignOutStatus;
    } catch (IOException e) {
        Log.w(TAG, "Canceled", e);
        return FAILED_ALL;
    }
}
Also used : IOException(java.io.IOException) Result(com.okta.oidc.results.Result) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult)

Example 9 with Result

use of com.okta.oidc.results.Result in project okta-oidc-android by okta.

the class SyncAuthClientTest method signInNative.

@Test
public void signInNative() throws AuthorizationException, OktaRepository.EncryptionException {
    String nonce = CodeVerifierUtil.generateRandomState();
    String state = CodeVerifierUtil.generateRandomState();
    String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
    AuthenticationPayload payload = new AuthenticationPayload.Builder().addParameter("nonce", nonce).setState(state).build();
    mEndPoint.enqueueNativeRequestSuccess(state);
    mEndPoint.enqueueTokenSuccess(jws);
    Result result = mSyncNativeAuth.signIn(SESSION_TOKEN, payload);
    assertNotNull(result);
    Tokens tokens = new Tokens(mOktaState.getTokenResponse());
    assertNotNull(tokens);
    assertNotNull(tokens.getAccessToken());
    assertNotNull(tokens.getRefreshToken());
    assertNotNull(tokens.getIdToken());
}
Also used : AuthenticationPayload(com.okta.oidc.AuthenticationPayload) Result(com.okta.oidc.results.Result) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

Aggregations

Result (com.okta.oidc.results.Result)9 StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)5 Test (org.junit.Test)5 AuthenticationPayload (com.okta.oidc.AuthenticationPayload)4 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)3 AuthorizationException (com.okta.oidc.util.AuthorizationException)3 AnyThread (androidx.annotation.AnyThread)2 NonNull (androidx.annotation.NonNull)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Uri (android.net.Uri)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Nullable (androidx.annotation.Nullable)1