use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.
the class OktaStateTest method getAuthorizeRequest.
@Test
public void getAuthorizeRequest() throws OktaRepository.EncryptionException, AuthorizationException {
WebRequest authorizedRequest = TestValues.getAuthorizeRequest(TestValues.getConfigWithUrl(CUSTOM_URL), null);
mOktaState.save(authorizedRequest);
AuthorizeRequest expected = (AuthorizeRequest) mOktaState.getAuthorizeRequest();
assertNotNull(expected);
assertEquals(authorizedRequest.persist(), expected.persist());
}
use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.
the class SyncWebAuthClientImpl method processSignInResult.
@NonNull
private Result processSignInResult(StateResult result) {
if (result == null) {
return Result.error(new AuthorizationException("Result is empty", new NullPointerException()));
}
switch(result.getStatus()) {
case CANCELED:
return Result.cancel();
case ERROR:
return Result.error(result.getException());
case AUTHORIZED:
mOktaState.setCurrentState(State.TOKEN_EXCHANGE);
TokenResponse response;
try {
WebRequest authorizedRequest = mOktaState.getAuthorizeRequest();
ProviderConfiguration providerConfiguration = mOktaState.getProviderConfiguration();
AuthorizeResponse authResponse = (AuthorizeResponse) result.getAuthorizationResponse();
if (isVerificationFlow((authResponse))) {
return processEmailVerification(authResponse);
}
validateResult(result.getAuthorizationResponse(), authorizedRequest);
TokenRequest request = tokenExchange((AuthorizeResponse) result.getAuthorizationResponse(), providerConfiguration, (AuthorizeRequest) authorizedRequest);
mCurrentRequest.set(new WeakReference<>(request));
response = request.executeRequest(mHttpClient);
mOktaState.save(response);
} catch (OktaRepository.EncryptionException e) {
return Result.error(EncryptionErrors.byEncryptionException(e));
} catch (AuthorizationException e) {
return Result.error(e);
}
return Result.success();
default:
return Result.error(new AuthorizationException("StateResult with invalid status: " + result.getStatus().name(), new IllegalStateException()));
}
}
use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.
the class SyncSessionClientImpl method migrateTo.
@Override
public void migrateTo(EncryptionManager manager) throws AuthorizationException {
try {
final ProviderConfiguration providerConfiguration = mOktaState.getProviderConfiguration();
final TokenResponse tokenResponse = mOktaState.getTokenResponse();
final WebRequest authorizedRequest = mOktaState.getAuthorizeRequest();
clear();
mOktaState.setEncryptionManager(manager);
mOktaState.save(providerConfiguration);
mOktaState.save(tokenResponse);
mOktaState.save(authorizedRequest);
} catch (OktaRepository.EncryptionException e) {
throw AuthorizationException.EncryptionErrors.byEncryptionException(e);
}
}
use of com.okta.oidc.net.request.web.WebRequest 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.net.request.web.WebRequest 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();
}
}
Aggregations