use of com.okta.oidc.net.response.TokenResponse 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);
}
}
use of com.okta.oidc.net.response.TokenResponse 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.response.TokenResponse in project okta-oidc-android by okta.
the class SessionClientImplTest method refreshTokenInParallel.
@Test
public void refreshTokenInParallel() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> cb = new MockRequestCallback<>(latch);
MockRequestCallback<Tokens, AuthorizationException> cb2 = new MockRequestCallback<>(latch);
new Thread(() -> mSessionClient.refreshToken(cb)).start();
new Thread(() -> mSessionClient.refreshToken(cb2)).start();
latch.await();
Tokens result = cb.getResult();
Tokens result2 = cb2.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());
assertEquals(result, result2);
}
use of com.okta.oidc.net.response.TokenResponse in project okta-oidc-android by okta.
the class SessionClientImplTest method requestsAreRunInSerial.
@Test
public void requestsAreRunInSerial() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
MockRequestCallback<UserInfo, AuthorizationException> userProfileCallback = new MockRequestCallback<>(latch);
mEndPoint.enqueueUserInfoSuccess();
mSessionClient.getUserProfile(userProfileCallback);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> refreshCallback = new MockRequestCallback<>(latch);
mSessionClient.refreshToken(refreshCallback);
latch.await();
UserInfo userInfoResult = userProfileCallback.getResult();
assertNotNull(userInfoResult);
assertEquals("John Doe", userInfoResult.get("name"));
assertEquals("Jimmy", userInfoResult.get("nickname"));
Tokens result = refreshCallback.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());
}
use of com.okta.oidc.net.response.TokenResponse 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());
}
Aggregations