use of com.okta.oidc.net.request.AuthorizedRequest in project okta-oidc-android by okta.
the class SyncSessionClientImplTest method userProfileRequest.
@Test
public void userProfileRequest() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
mOktaState.save(mTokenResponse);
mEndPoint.enqueueUserInfoSuccess();
AuthorizedRequest request = mSyncSessionClientImpl.userProfileRequest(mOktaState.getProviderConfiguration(), mTokenResponse);
JSONObject result = request.executeRequest(mHttpClient);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
assertThat(recordedRequest.getHeader("Authorization"), is("Bearer " + ACCESS_TOKEN));
assertThat(recordedRequest.getHeader("Accept"), is(ConnectionParameters.JSON_CONTENT_TYPE));
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
assertNotNull(result);
assertEquals("John Doe", result.getString("name"));
assertEquals("Jimmy", result.getString("nickname"));
}
use of com.okta.oidc.net.request.AuthorizedRequest in project okta-oidc-android by okta.
the class SyncSessionClientImplTest method userProfileRequestFailure.
@Test
public void userProfileRequestFailure() throws InterruptedException, AuthorizationException, OktaRepository.EncryptionException {
mOktaState.save(mTokenResponse);
mExpectedEx.expect(AuthorizationException.class);
mEndPoint.enqueueReturnUnauthorizedRevoked();
AuthorizedRequest request = mSyncSessionClientImpl.userProfileRequest(mOktaState.getProviderConfiguration(), mTokenResponse);
JSONObject result = request.executeRequest(mHttpClient);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
assertNull(result);
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
}
use of com.okta.oidc.net.request.AuthorizedRequest in project okta-oidc-android by okta.
the class SyncSessionClientImplTest method authorizedRequestFailure.
@Test
public void authorizedRequestFailure() throws InterruptedException, AuthorizationException, OktaRepository.EncryptionException {
// use userinfo for generic authorized request
mOktaState.save(mTokenResponse);
mExpectedEx.expect(AuthorizationException.class);
mEndPoint.enqueueReturnUnauthorizedRevoked();
Uri uri = Uri.parse(mProviderConfig.userinfo_endpoint);
HashMap<String, String> properties = new HashMap<>();
properties.put("state", CUSTOM_STATE);
AuthorizedRequest request = mSyncSessionClientImpl.createAuthorizedRequest(uri, properties, null, ConnectionParameters.RequestMethod.GET, mOktaState.getProviderConfiguration(), mTokenResponse);
JSONObject result = request.executeRequest(mHttpClient);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
assertThat(recordedRequest.getHeader("state"), is(CUSTOM_STATE));
assertThat(recordedRequest.getHeader("Authorization"), is("Bearer " + ACCESS_TOKEN));
assertThat(recordedRequest.getHeader("Accept"), is(ConnectionParameters.JSON_CONTENT_TYPE));
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
assertNull(result);
}
use of com.okta.oidc.net.request.AuthorizedRequest in project okta-oidc-android by okta.
the class SyncSessionClientImpl method getUserProfile.
@Override
public UserInfo getUserProfile() throws AuthorizationException {
try {
ProviderConfiguration providerConfiguration = mOktaState.getProviderConfiguration();
TokenResponse tokenResponse = mOktaState.getTokenResponse();
AuthorizedRequest request = userProfileRequest(providerConfiguration, tokenResponse);
JSONObject userInfo = request.executeRequest(mHttpClient);
mCurrentRequest.set(new WeakReference<>(request));
return new UserInfo(userInfo);
} catch (OktaRepository.EncryptionException e) {
throw AuthorizationException.EncryptionErrors.byEncryptionException(e);
}
}
use of com.okta.oidc.net.request.AuthorizedRequest in project okta-oidc-android by okta.
the class SyncSessionClientImpl method authorizedRequest.
public JSONObject authorizedRequest(@NonNull Uri uri, @Nullable Map<String, String> properties, @Nullable Map<String, String> postParameters, @NonNull ConnectionParameters.RequestMethod method) throws AuthorizationException {
try {
ProviderConfiguration providerConfiguration = mOktaState.getProviderConfiguration();
TokenResponse tokenResponse = mOktaState.getTokenResponse();
AuthorizedRequest request = createAuthorizedRequest(uri, properties, postParameters, method, providerConfiguration, tokenResponse);
mCurrentRequest.set(new WeakReference<>(request));
return request.executeRequest(mHttpClient);
} catch (OktaRepository.EncryptionException e) {
throw AuthorizationException.EncryptionErrors.byEncryptionException(e);
}
}
Aggregations