Search in sources :

Example 6 with UserInfo

use of com.okta.oidc.net.response.UserInfo in project okta-oidc-android by okta.

the class SessionClientImplTest method getUserProfile.

@Test
public void getUserProfile() throws InterruptedException, JSONException {
    mEndPoint.enqueueUserInfoSuccess();
    final CountDownLatch latch = new CountDownLatch(1);
    MockRequestCallback<UserInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
    mSessionClient.getUserProfile(cb);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    latch.await();
    UserInfo result = cb.getResult();
    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.get("name"));
    assertEquals("Jimmy", result.get("nickname"));
}
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)

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