use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SyncAuthClientImpl method signIn.
@WorkerThread
@Override
public Result signIn(String sessionToken, @Nullable AuthenticationPayload payload) {
try {
mCancel.set(false);
ProviderConfiguration providerConfiguration = obtainNewConfiguration();
checkIfCanceled();
mOktaState.setCurrentState(State.SIGN_IN_REQUEST);
NativeAuthorizeRequest request = nativeAuthorizeRequest(sessionToken, providerConfiguration, payload);
mCurrentRequest.set(new WeakReference<>(request));
// Save the nativeAuth request in a AuthRequest because it is needed to verify results.
AuthorizeRequest authRequest = new AuthorizeRequest(request.getParameters());
mOktaState.save(authRequest);
AuthorizeResponse authResponse = request.executeRequest(mHttpClient);
checkIfCanceled();
// This flow should never happen but if it does throw a exception.
if (isVerificationFlow(authResponse)) {
return Result.error(new AuthorizationException("Email verification required. Session: " + authResponse.getSessionHint(), null));
}
validateResult(authResponse, authRequest);
mOktaState.setCurrentState(State.TOKEN_EXCHANGE);
TokenRequest requestToken = tokenExchange(authResponse, providerConfiguration, authRequest);
mCurrentRequest.set(new WeakReference<>(requestToken));
TokenResponse tokenResponse = requestToken.executeRequest(mHttpClient);
mOktaState.save(tokenResponse);
return Result.success();
} catch (AuthorizationException e) {
return Result.error(e);
} catch (IOException e) {
return Result.cancel();
} catch (Exception e) {
return Result.error(new AuthorizationException(OTHER.code, e.getMessage(), e));
} finally {
resetCurrentState();
}
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SyncWebAuthClientImpl method signOutOfOkta.
@Override
@AnyThread
public Result signOutOfOkta(@NonNull final Activity activity) {
try {
mOktaState.setCurrentState(State.SIGN_OUT_REQUEST);
WebRequest request;
request = new LogoutRequest.Builder().provideConfiguration(mOktaState.getProviderConfiguration()).config(mOidcConfig).tokenResponse(mOktaState.getTokenResponse()).state(CodeVerifierUtil.generateRandomState()).create();
mOktaState.save(request);
StateResult logoutResult = startSignOut(activity, request);
return processSignOutResult(logoutResult);
} catch (InterruptedException e) {
return Result.cancel();
} catch (OktaRepository.EncryptionException e) {
return Result.error(EncryptionErrors.byEncryptionException(e));
} catch (AuthorizationException e) {
return Result.error(e);
} catch (NullPointerException e) {
return Result.error(new AuthorizationException(e.getMessage(), e));
} finally {
resetCurrentState();
}
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SyncWebAuthClientImpl method signIn.
@Override
@WorkerThread
public Result signIn(@NonNull final Activity activity, @Nullable AuthenticationPayload payload) {
mCancel.set(false);
try {
if (!isRedirectUrisRegistered(mOidcConfig.getRedirectUri(), activity)) {
String errorDescription = "No uri registered to handle redirect " + "or multiple applications registered";
Log.e(TAG, errorDescription);
throw new AuthorizationException(TYPE_OAUTH_REGISTRATION_ERROR, INVALID_REDIRECT_URI.code, INVALID_REDIRECT_URI.error, errorDescription, null, null);
}
ProviderConfiguration configuration = obtainNewConfiguration();
checkIfCanceled();
WebRequest request = new AuthorizeRequest.Builder().config(mOidcConfig).providerConfiguration(configuration).authenticationPayload(payload).create();
mOktaState.save(request);
mOktaState.setCurrentState(State.SIGN_IN_REQUEST);
StateResult authResult = startSignIn(activity, request);
return processSignInResult(authResult);
} catch (AuthorizationException e) {
return Result.error(e);
} catch (IOException | InterruptedException e) {
return Result.cancel();
} catch (OktaRepository.EncryptionException e) {
return Result.error(EncryptionErrors.byEncryptionException(e));
} finally {
resetCurrentState();
}
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImpl method refreshToken.
public void refreshToken(final RequestCallback<Tokens, AuthorizationException> cb) {
// Wrap the callback from the app because we want to be consistent in
// returning a Tokens object instead of a TokenResponse.
boolean isEmpty;
if (Thread.holdsLock(refreshTokenRequestCallbacks)) {
throw new RuntimeException("refreshToken can't be called from callback.");
}
CallbackWrapper<Tokens, AuthorizationException> wrapper = new CallbackWrapper<>(cb);
synchronized (refreshTokenRequestCallbacks) {
isEmpty = refreshTokenRequestCallbacks.isEmpty();
refreshTokenRequestCallbacks.add(wrapper);
}
if (isEmpty) {
executeSerial(wrapper, () -> {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
Tokens result = mSyncSessionClient.refreshToken();
mDispatcher.submitResults(() -> {
synchronized (refreshTokenRequestCallbacks) {
for (RequestCallback<Tokens, AuthorizationException> callback : refreshTokenRequestCallbacks) {
callback.onSuccess(result);
}
refreshTokenRequestCallbacks.clear();
}
});
} catch (AuthorizationException ae) {
mDispatcher.submitResults(() -> {
synchronized (refreshTokenRequestCallbacks) {
for (RequestCallback<Tokens, AuthorizationException> callback : refreshTokenRequestCallbacks) {
callback.onError(ae.error, ae);
}
refreshTokenRequestCallbacks.clear();
}
});
} catch (Exception ex) {
mDispatcher.submitResults(() -> {
synchronized (refreshTokenRequestCallbacks) {
for (RequestCallback<Tokens, AuthorizationException> callback : refreshTokenRequestCallbacks) {
callback.onError(ex.getMessage(), new AuthorizationException(ex.getMessage(), ex));
}
refreshTokenRequestCallbacks.clear();
}
});
}
});
}
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImpl method introspectToken.
public void introspectToken(String token, String tokenType, final RequestCallback<IntrospectInfo, AuthorizationException> cb) {
CallbackWrapper<IntrospectInfo, AuthorizationException> wrapper = new CallbackWrapper<>(cb);
executeSerial(wrapper, () -> {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
IntrospectInfo introspectInfo = mSyncSessionClient.introspectToken(token, tokenType);
mDispatcher.submitResults(() -> wrapper.onSuccess(introspectInfo));
} catch (AuthorizationException ae) {
mDispatcher.submitResults(() -> wrapper.onError(ae.error, ae));
} catch (Exception ex) {
mDispatcher.submitResults(() -> wrapper.onError(ex.getMessage(), new AuthorizationException(ex.getMessage(), ex)));
}
});
}
Aggregations