Search in sources :

Example 21 with TokenResponse

use of com.okta.oidc.net.response.TokenResponse in project okta-oidc-android by okta.

the class OktaStateTest method validateDelete.

@Test
public void validateDelete() throws OktaRepository.EncryptionException {
    TokenResponse tokenResponse = TestValues.getTokenResponse();
    ProviderConfiguration providerConfiguration = TestValues.getProviderConfiguration(CUSTOM_URL);
    mOktaState.save(tokenResponse);
    mOktaState.save(providerConfiguration);
    mOktaState.delete(tokenResponse);
    assertNull(mOktaState.getTokenResponse());
    assertNotNull(mOktaState.getProviderConfiguration());
}
Also used : TokenResponse(com.okta.oidc.net.response.TokenResponse) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) Test(org.junit.Test)

Example 22 with TokenResponse

use of com.okta.oidc.net.response.TokenResponse in project okta-oidc-android by okta.

the class HttpResponseTest method jsonOKResponse.

@Test
public void jsonOKResponse() throws Exception {
    mServer.enqueue(new MockResponse().setResponseCode(HTTP_OK).addHeader(CONTENT_TYPE, JSON_CONTENT_TYPE).setBody(TOKEN_SUCCESS));
    URL url = mServer.url("/").url();
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestProperty("Accept-Language", "en-US");
    connection.setRequestProperty("Content-Length", TOKEN_SUCCESS.length() + "");
    MockOktaHttpClient httpClient = new MockOktaHttpClient(connection);
    InputStream inputStream;
    try {
        inputStream = connection.getInputStream();
    } catch (IOException exception) {
        inputStream = connection.getErrorStream();
    }
    HttpResponse response = new HttpResponse(HTTP_OK, httpClient.getHeaderFields(), httpClient.getContentLength(), inputStream, httpClient);
    Map<String, List<String>> headers = response.getHeaders();
    int contentLength = response.getContentLength();
    int status = response.getStatusCode();
    JSONObject jsonObject = response.asJson();
    TokenResponse tokenResponse = new Gson().fromJson(jsonObject.toString(), TokenResponse.class);
    assertNotNull(tokenResponse);
    assertEquals(HTTP_OK, status);
    assertNotNull(headers);
    assertEquals(contentLength, TOKEN_SUCCESS.length());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.JSONObject) TokenResponse(com.okta.oidc.net.response.TokenResponse) List(java.util.List) Test(org.junit.Test)

Example 23 with TokenResponse

use of com.okta.oidc.net.response.TokenResponse in project okta-oidc-android by okta.

the class RefreshTokenRequestTest method executeRequestSuccess.

@Test
public void executeRequestSuccess() throws AuthorizationException {
    String jws = TestValues.getJwt(mEndPoint.getUrl(), CUSTOM_NONCE, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    TokenResponse response = mRequest.executeRequest(mHttpClient);
    assertNotNull(response);
    assertEquals(response.getIdToken(), jws);
}
Also used : TokenResponse(com.okta.oidc.net.response.TokenResponse) Test(org.junit.Test)

Example 24 with TokenResponse

use of com.okta.oidc.net.response.TokenResponse in project okta-oidc-android by okta.

the class AuthorizedRequestTest method setUp.

@Before
public void setUp() throws Exception {
    mEndPoint = new MockEndPoint();
    String url = mEndPoint.getUrl();
    OIDCConfig config = TestValues.getConfigWithUrl(url);
    mProviderConfig = TestValues.getProviderConfiguration(url);
    mTokenResponse = new Gson().fromJson(JsonStrings.TOKEN_RESPONSE, TokenResponse.class);
    mClientFactory = new HttpClientFactory();
    mClientFactory.setClientType(mClientType);
    mHttpClient = mClientFactory.build();
    mRequest = HttpRequestBuilder.newAuthorizedRequest().uri(Uri.parse(mEndPoint.getUrl())).httpRequestMethod(ConnectionParameters.RequestMethod.POST).config(config).providerConfiguration(mProviderConfig).tokenResponse(mTokenResponse).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) HttpClientFactory(com.okta.oidc.util.HttpClientFactory) Before(org.junit.Before)

Example 25 with TokenResponse

use of com.okta.oidc.net.response.TokenResponse in project okta-oidc-android by okta.

the class TokenRequestTest method executeRequestSuccess.

@Test
public void executeRequestSuccess() throws AuthorizationException {
    String jws = TestValues.getJwt(mEndPoint.getUrl(), CUSTOM_NONCE, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    TokenResponse response = mRequest.executeRequest(mHttpClient);
    assertNotNull(response);
    assertEquals(response.getIdToken(), jws);
}
Also used : TokenResponse(com.okta.oidc.net.response.TokenResponse) Test(org.junit.Test)

Aggregations

TokenResponse (com.okta.oidc.net.response.TokenResponse)25 Test (org.junit.Test)16 ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)7 AuthorizationException (com.okta.oidc.util.AuthorizationException)6 OktaRepository (com.okta.oidc.storage.OktaRepository)5 Gson (com.google.gson.Gson)4 Tokens (com.okta.oidc.Tokens)4 TokenRequest (com.okta.oidc.net.request.TokenRequest)4 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)4 RefreshTokenRequest (com.okta.oidc.net.request.RefreshTokenRequest)3 AuthorizeRequest (com.okta.oidc.net.request.web.AuthorizeRequest)3 MockRequestCallback (com.okta.oidc.util.MockRequestCallback)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 JSONObject (org.json.JSONObject)3 OIDCConfig (com.okta.oidc.OIDCConfig)2 AuthorizedRequest (com.okta.oidc.net.request.AuthorizedRequest)2 RevokeTokenRequest (com.okta.oidc.net.request.RevokeTokenRequest)2 WebRequest (com.okta.oidc.net.request.web.WebRequest)2 UserInfo (com.okta.oidc.net.response.UserInfo)2