Search in sources :

Example 1 with ProviderConfiguration

use of com.okta.oidc.net.request.ProviderConfiguration in project okta-oidc-android by okta.

the class SyncWebAuthClientTest method configurationRequestFailure.

@Test
public void configurationRequestFailure() throws AuthorizationException, InterruptedException {
    mExpectedEx.expect(AuthorizationException.class);
    mEndPoint.enqueueConfigurationFailure();
    ConfigurationRequest request = mSyncWebAuth.configurationRequest();
    ProviderConfiguration configuration = request.executeRequest(mHttpClient);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    assertThat(recordedRequest.getPath(), equalTo("//.well-known/openid-configuration?client_id=CLIENT_ID"));
    assertNull(configuration);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConfigurationRequest(com.okta.oidc.net.request.ConfigurationRequest) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) Test(org.junit.Test)

Example 2 with ProviderConfiguration

use of com.okta.oidc.net.request.ProviderConfiguration in project okta-oidc-android by okta.

the class SyncWebAuthClientTest method configurationRequest.

@Test
public void configurationRequest() throws AuthorizationException, InterruptedException {
    mEndPoint.enqueueConfigurationSuccess();
    ConfigurationRequest request = mSyncWebAuth.configurationRequest();
    ProviderConfiguration configuration = request.executeRequest(mHttpClient);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    assertThat(recordedRequest.getPath(), equalTo("//.well-known/openid-configuration?client_id=CLIENT_ID"));
    assertNotNull(configuration);
    assertEquals(mGson.fromJson(PROVIDER_CONFIG, ProviderConfiguration.class).persist(), configuration.persist());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConfigurationRequest(com.okta.oidc.net.request.ConfigurationRequest) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) Test(org.junit.Test)

Example 3 with ProviderConfiguration

use of com.okta.oidc.net.request.ProviderConfiguration in project okta-oidc-android by okta.

the class HttpClientImplTest method setUp.

@Before
public void setUp() throws Exception {
    mEndPoint = new MockEndPoint();
    String url = mEndPoint.getUrl();
    OIDCConfig config = TestValues.getConfigWithUrl(url);
    ProviderConfiguration providerConfiguration = TestValues.getProviderConfiguration(url);
    TokenResponse tokenResponse = new Gson().fromJson(JsonStrings.TOKEN_RESPONSE, TokenResponse.class);
    mHttpClient = new HttpClientImpl();
    mRequest = HttpRequestBuilder.newAuthorizedRequest().uri(Uri.parse(mEndPoint.getUrl())).httpRequestMethod(ConnectionParameters.RequestMethod.POST).config(config).providerConfiguration(providerConfiguration).tokenResponse(tokenResponse).createRequest();
}
Also used : TokenResponse(com.okta.oidc.net.response.TokenResponse) MockEndPoint(com.okta.oidc.util.MockEndPoint) OIDCConfig(com.okta.oidc.OIDCConfig) Gson(com.google.gson.Gson) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) Before(org.junit.Before)

Example 4 with ProviderConfiguration

use of com.okta.oidc.net.request.ProviderConfiguration in project okta-oidc-android by okta.

the class TestValues method getProviderConfiguration.

public static ProviderConfiguration getProviderConfiguration(String url) {
    ProviderConfiguration configuration = new ProviderConfiguration();
    configuration.issuer = url;
    configuration.revocation_endpoint = url + REVOCATION_ENDPOINT;
    configuration.authorization_endpoint = url + AUTHORIZATION_ENDPOINT;
    configuration.token_endpoint = url + TOKEN_ENDPOINT;
    configuration.introspection_endpoint = url + INTROSPECT_ENDPOINT;
    configuration.jwks_uri = url + JWKS_ENDPOINT;
    configuration.registration_endpoint = url + REGISTRATION_ENDPOINT;
    configuration.end_session_endpoint = url + END_SESSION_ENDPOINT;
    configuration.userinfo_endpoint = url + USERINFO_ENDPOINT;
    return configuration;
}
Also used : ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration)

Example 5 with ProviderConfiguration

use of com.okta.oidc.net.request.ProviderConfiguration 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()));
    }
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) WebRequest(com.okta.oidc.net.request.web.WebRequest) AuthorizationException(com.okta.oidc.util.AuthorizationException) OktaRepository(com.okta.oidc.storage.OktaRepository) TokenRequest(com.okta.oidc.net.request.TokenRequest) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) NonNull(androidx.annotation.NonNull)

Aggregations

ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)15 TokenResponse (com.okta.oidc.net.response.TokenResponse)7 OktaRepository (com.okta.oidc.storage.OktaRepository)6 Test (org.junit.Test)4 ConfigurationRequest (com.okta.oidc.net.request.ConfigurationRequest)3 WebRequest (com.okta.oidc.net.request.web.WebRequest)3 AuthorizationException (com.okta.oidc.util.AuthorizationException)3 Uri (android.net.Uri)2 WorkerThread (androidx.annotation.WorkerThread)2 AuthorizedRequest (com.okta.oidc.net.request.AuthorizedRequest)2 TokenRequest (com.okta.oidc.net.request.TokenRequest)2 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)2 IOException (java.io.IOException)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 NonNull (androidx.annotation.NonNull)1 RestrictTo (androidx.annotation.RestrictTo)1 Gson (com.google.gson.Gson)1 StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)1 OIDCConfig (com.okta.oidc.OIDCConfig)1 NativeAuthorizeRequest (com.okta.oidc.net.request.NativeAuthorizeRequest)1