Search in sources :

Example 1 with RefreshTokenRequest

use of com.okta.oidc.net.request.RefreshTokenRequest 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 2 with RefreshTokenRequest

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

the class SyncSessionClientImpl method refreshToken.

@Override
public Tokens refreshToken() throws AuthorizationException {
    try {
        RefreshTokenRequest request = refreshTokenRequest(mOktaState.getProviderConfiguration(), mOktaState.getTokenResponse());
        mCurrentRequest.set(new WeakReference<>(request));
        TokenResponse tokenResponse = request.executeRequest(mHttpClient);
        mOktaState.save(tokenResponse);
        return new Tokens(tokenResponse);
    } catch (OktaRepository.EncryptionException e) {
        throw AuthorizationException.EncryptionErrors.byEncryptionException(e);
    }
}
Also used : RefreshTokenRequest(com.okta.oidc.net.request.RefreshTokenRequest) TokenResponse(com.okta.oidc.net.response.TokenResponse) OktaRepository(com.okta.oidc.storage.OktaRepository) Tokens(com.okta.oidc.Tokens)

Example 3 with RefreshTokenRequest

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

the class SyncSessionClientImplTest method refreshTokenRequest.

@Test
public void refreshTokenRequest() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
    mOktaState.save(mTokenResponse);
    RefreshTokenRequest request = mSyncSessionClientImpl.refreshTokenRequest(mOktaState.getProviderConfiguration(), mTokenResponse);
    String nonce = CodeVerifierUtil.generateRandomState();
    String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    TokenResponse response = request.executeRequest(mHttpClient);
    assertNotNull(response);
    TokenResponse original = mGson.fromJson(String.format(TOKEN_SUCCESS, jws), TokenResponse.class);
    assertEquals(original.getIdToken(), response.getIdToken());
    assertEquals(original.getRefreshToken(), response.getRefreshToken());
    assertEquals(original.getIdToken(), response.getIdToken());
}
Also used : RefreshTokenRequest(com.okta.oidc.net.request.RefreshTokenRequest) TokenResponse(com.okta.oidc.net.response.TokenResponse) Test(org.junit.Test)

Aggregations

RefreshTokenRequest (com.okta.oidc.net.request.RefreshTokenRequest)3 TokenResponse (com.okta.oidc.net.response.TokenResponse)3 Test (org.junit.Test)2 Tokens (com.okta.oidc.Tokens)1 OktaRepository (com.okta.oidc.storage.OktaRepository)1