use of com.okta.oidc.net.response.UserInfo in project okta-oidc-android by okta.
the class SessionClientImplTest method getUserProfileFailure.
@Test
public void getUserProfileFailure() throws InterruptedException, JSONException {
mEndPoint.enqueueReturnUnauthorizedRevoked();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<UserInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.getUserProfile(cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
assertEquals(TYPE_GENERAL_ERROR, cb.getException().type);
}
use of com.okta.oidc.net.response.UserInfo 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.response.UserInfo in project okta-oidc-android by okta.
the class SessionClientImpl method getUserProfile.
public void getUserProfile(RequestCallback<UserInfo, AuthorizationException> cb) {
CallbackWrapper<UserInfo, AuthorizationException> wrapper = new CallbackWrapper<>(cb);
executeSerial(wrapper, () -> {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
UserInfo userInfo = mSyncSessionClient.getUserProfile();
mDispatcher.submitResults(() -> wrapper.onSuccess(userInfo));
} catch (AuthorizationException ae) {
mDispatcher.submitResults(() -> wrapper.onError(ae.error, ae));
} catch (Exception ex) {
mDispatcher.submitResults(() -> wrapper.onError(ex.getMessage(), new AuthorizationException(ex.getMessage(), ex)));
}
});
}
use of com.okta.oidc.net.response.UserInfo in project okta-oidc-android by okta.
the class SampleActivity method getProfile.
private void getProfile() {
showNetworkProgress(true);
SessionClient client = getSessionClient();
client.getUserProfile(new RequestCallback<UserInfo, AuthorizationException>() {
@Override
public void onSuccess(@NonNull UserInfo result) {
mTvStatus.setText(result.toString());
showNetworkProgress(false);
}
@Override
public void onError(String error, AuthorizationException exception) {
Log.d(TAG, error, exception.getCause());
mTvStatus.setText("Error : " + exception.errorDescription);
showNetworkProgress(false);
}
});
}
use of com.okta.oidc.net.response.UserInfo 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());
}
Aggregations