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();
}
});
}
});
}
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());
});
}
});
}
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;
}
}
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());
}
Aggregations