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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations