Search in sources :

Example 1 with TokenResponse

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

the class SyncWebAuthClientTest method tokenExchangeSuccess.

@Test
public void tokenExchangeSuccess() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
    String codeVerifier = CodeVerifierUtil.generateRandomCodeVerifier();
    String nonce = CodeVerifierUtil.generateRandomState();
    AuthorizeRequest request = new AuthorizeRequest.Builder().codeVerifier(codeVerifier).authorizeEndpoint(mProviderConfig.authorization_endpoint).redirectUri(mConfig.getRedirectUri().toString()).scope("openid", "email", "profile").nonce(nonce).create();
    mOktaState.save(request);
    AuthorizeResponse response = AuthorizeResponse.fromUri(Uri.parse("com.okta.test:/callback?code=CODE&state=CUSTOM_STATE"));
    String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    TokenRequest tokenRequest = mSyncWebAuth.tokenExchange(response, mOktaState.getProviderConfiguration(), (AuthorizeRequest) mOktaState.getAuthorizeRequest());
    TokenResponse tokenResponse = tokenRequest.executeRequest(mHttpClient);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    assertThat(recordedRequest.getPath(), equalTo("/token"));
    assertNotNull(tokenResponse);
    assertEquals(tokenResponse.getIdToken(), jws);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) TokenRequest(com.okta.oidc.net.request.TokenRequest) RevokeTokenRequest(com.okta.oidc.net.request.RevokeTokenRequest) Test(org.junit.Test)

Example 2 with TokenResponse

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

the class SyncWebAuthClientTest method tokenExchangeFailure.

@Test
public void tokenExchangeFailure() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
    mExpectedEx.expect(AuthorizationException.class);
    String codeVerifier = CodeVerifierUtil.generateRandomCodeVerifier();
    String nonce = CodeVerifierUtil.generateRandomState();
    AuthorizeRequest request = new AuthorizeRequest.Builder().codeVerifier(codeVerifier).authorizeEndpoint(mProviderConfig.authorization_endpoint).redirectUri(mConfig.getRedirectUri().toString()).scope(SCOPES).nonce(nonce).create();
    mOktaState.save(request);
    AuthorizeResponse response = AuthorizeResponse.fromUri(Uri.parse("com.okta.test:/callback?code=CODE&state=CUSTOM_STATE"));
    mEndPoint.enqueueReturnInvalidClient();
    TokenRequest tokenRequest = mSyncWebAuth.tokenExchange(response, mOktaState.getProviderConfiguration(), (AuthorizeRequest) mOktaState.getAuthorizeRequest());
    TokenResponse tokenResponse = tokenRequest.executeRequest(mHttpClient);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    assertThat(recordedRequest.getPath(), equalTo("/token"));
    assertNull(tokenResponse);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) TokenRequest(com.okta.oidc.net.request.TokenRequest) RevokeTokenRequest(com.okta.oidc.net.request.RevokeTokenRequest) Test(org.junit.Test)

Example 3 with TokenResponse

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

the class SyncSessionClientImplTest method refreshTokenRequestFailure.

@Test
public void refreshTokenRequestFailure() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
    mOktaState.save(mTokenResponse);
    mExpectedEx.expect(AuthorizationException.class);
    mEndPoint.enqueueReturnInvalidClient();
    RefreshTokenRequest request = mSyncSessionClientImpl.refreshTokenRequest(mOktaState.getProviderConfiguration(), mTokenResponse);
    TokenResponse response = request.executeRequest(mHttpClient);
    assertNull(response);
}
Also used : RefreshTokenRequest(com.okta.oidc.net.request.RefreshTokenRequest) TokenResponse(com.okta.oidc.net.response.TokenResponse) Test(org.junit.Test)

Example 4 with TokenResponse

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

the class SessionClientImplTest method refreshToken.

@Test
public void refreshToken() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    String nonce = CodeVerifierUtil.generateRandomState();
    String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    MockRequestCallback<Tokens, AuthorizationException> cb = new MockRequestCallback<>(latch);
    mSessionClient.refreshToken(cb);
    latch.await();
    Tokens result = cb.getResult();
    TokenResponse original = mGson.fromJson(String.format(TOKEN_SUCCESS, jws), TokenResponse.class);
    assertEquals(original.getIdToken(), result.getIdToken());
    assertEquals(original.getRefreshToken(), result.getRefreshToken());
    assertEquals(original.getIdToken(), result.getIdToken());
}
Also used : MockRequestCallback(com.okta.oidc.util.MockRequestCallback) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizationException(com.okta.oidc.util.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

Example 5 with TokenResponse

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

the class TokensTest method validateTokenInit_fromInvalidTokenResponse.

@Test(expected = NumberFormatException.class)
public void validateTokenInit_fromInvalidTokenResponse() {
    TokenResponse tokenResponse = TokenResponse.RESTORE.restore(invalidTokenResponsePayload);
    new Tokens(tokenResponse);
}
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