From 59edd73f4fe6716ae32344f39c9b431105852117 Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Thu, 24 Nov 2016 18:31:36 -0300 Subject: [PATCH] fix getProfileAfter sync --- .../request/ProfileRequest.java | 3 +-- .../AuthenticationAPIClientTest.java | 23 +++++++++++++++++++ .../request/ProfileRequestTest.java | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/auth0/src/main/java/com/auth0/android/authentication/request/ProfileRequest.java b/auth0/src/main/java/com/auth0/android/authentication/request/ProfileRequest.java index 8f7a5b628..f9538de0a 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/request/ProfileRequest.java +++ b/auth0/src/main/java/com/auth0/android/authentication/request/ProfileRequest.java @@ -97,7 +97,6 @@ public void start(final BaseCallback ca public void onSuccess(final Credentials credentials) { userInfoRequest .addHeader(HEADER_AUTHORIZATION, "Bearer " + credentials.getAccessToken()) - .addParameter(ACCESS_TOKEN_KEY, credentials.getAccessToken()) .start(new BaseCallback() { @Override public void onSuccess(UserProfile profile) { @@ -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); } diff --git a/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java b/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java index 73689d5cd..a5e2ae7af 100755 --- a/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java +++ b/auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.java @@ -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 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() diff --git a/auth0/src/test/java/com/auth0/android/authentication/request/ProfileRequestTest.java b/auth0/src/test/java/com/auth0/android/authentication/request/ProfileRequestTest.java index 4435d83da..6683b827c 100644 --- a/auth0/src/test/java/com/auth0/android/authentication/request/ProfileRequestTest.java +++ b/auth0/src/test/java/com/auth0/android/authentication/request/ProfileRequestTest.java @@ -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() { @Override public Object answer(InvocationOnMock invocation) throws Throwable {