Search in sources :

Example 1 with UserInfo

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockRequestCallback(com.okta.oidc.util.MockRequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) UserInfo(com.okta.oidc.net.response.UserInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with UserInfo

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);
    }
}
Also used : AuthorizedRequest(com.okta.oidc.net.request.AuthorizedRequest) TokenResponse(com.okta.oidc.net.response.TokenResponse) JSONObject(org.json.JSONObject) OktaRepository(com.okta.oidc.storage.OktaRepository) UserInfo(com.okta.oidc.net.response.UserInfo) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration)

Example 3 with UserInfo

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)));
        }
    });
}
Also used : AuthorizationException(com.okta.oidc.util.AuthorizationException) UserInfo(com.okta.oidc.net.response.UserInfo) AuthorizationException(com.okta.oidc.util.AuthorizationException)

Example 4 with UserInfo

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);
        }
    });
}
Also used : SessionClient(com.okta.oidc.clients.sessions.SessionClient) AuthorizationException(com.okta.oidc.util.AuthorizationException) UserInfo(com.okta.oidc.net.response.UserInfo)

Example 5 with UserInfo

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());
}
Also used : MockRequestCallback(com.okta.oidc.util.MockRequestCallback) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizationException(com.okta.oidc.util.AuthorizationException) UserInfo(com.okta.oidc.net.response.UserInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

Aggregations

UserInfo (com.okta.oidc.net.response.UserInfo)6 AuthorizationException (com.okta.oidc.util.AuthorizationException)5 MockRequestCallback (com.okta.oidc.util.MockRequestCallback)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 TokenResponse (com.okta.oidc.net.response.TokenResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Tokens (com.okta.oidc.Tokens)1 SessionClient (com.okta.oidc.clients.sessions.SessionClient)1 AuthorizedRequest (com.okta.oidc.net.request.AuthorizedRequest)1 ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)1 OktaRepository (com.okta.oidc.storage.OktaRepository)1 JSONObject (org.json.JSONObject)1