Skip to content

Commit

Permalink
fix getProfileAfter sync
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Nov 24, 2016
1 parent 098c234 commit 59edd73
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void start(final BaseCallback<Authentication, AuthenticationException> ca
public void onSuccess(final Credentials credentials) {
userInfoRequest
.addHeader(HEADER_AUTHORIZATION, "Bearer " + credentials.getAccessToken())
.addParameter(ACCESS_TOKEN_KEY, credentials.getAccessToken())
.start(new BaseCallback<UserProfile, AuthenticationException>() {
@Override
public void onSuccess(UserProfile profile) {
Expand Down Expand Up @@ -128,7 +127,7 @@ public void onFailure(AuthenticationException error) {
public Authentication execute() throws Auth0Exception {
Credentials credentials = credentialsRequest.execute();
UserProfile profile = userInfoRequest
.addParameter(ACCESS_TOKEN_KEY, credentials.getAccessToken())
.addHeader(HEADER_AUTHORIZATION, "Bearer " + credentials.getAccessToken())
.execute();
return new Authentication(profile, credentials);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,29 @@ public void shouldFetchProfileAfterLoginRequest() throws Exception {
assertThat(callback, hasPayloadOfType(Authentication.class));
}

@Test
public void shouldFetchProfileSyncAfterLoginRequest() throws Exception {
mockAPI.willReturnSuccessfulLogin()
.willReturnTokenInfo();

Authentication authentication = client.getProfileAfter(client.login(SUPPORT_AUTH0_COM, "voidpassword", MY_CONNECTION))
.execute();

final RecordedRequest firstRequest = mockAPI.takeRequest();
assertThat(firstRequest.getPath(), equalTo("/oauth/ro"));

Map<String, String> body = bodyFromRequest(firstRequest);
assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
assertThat(body, hasEntry("password", "voidpassword"));
assertThat(body, hasEntry("connection", MY_CONNECTION));

final RecordedRequest secondRequest = mockAPI.takeRequest();
assertThat(secondRequest.getHeader("Authorization"), is("Bearer " + AuthenticationAPI.ACCESS_TOKEN));
assertThat(secondRequest.getPath(), equalTo("/userinfo"));

assertThat(authentication, is(notNullValue()));
}

@Test
public void shouldGetOAuthTokensUsingCodeVerifier() throws Exception {
mockAPI.willReturnTokens()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
});
final UserProfile userProfile = mock(UserProfile.class);
when(userInfoMockRequest.addParameter(anyString(), anyObject())).thenReturn(userInfoMockRequest);
when(userInfoMockRequest.addHeader(anyString(), anyString())).thenReturn(userInfoMockRequest);
when(userInfoMockRequest.execute()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Expand Down

0 comments on commit 59edd73

Please sign in to comment.