|
26 | 26 |
|
27 | 27 |
|
28 | 28 | import com.auth0.Auth0; |
29 | | -import com.auth0.Auth0Exception; |
30 | 29 | import com.auth0.authentication.result.Authentication; |
31 | 30 | import com.auth0.authentication.result.Credentials; |
32 | 31 | import com.auth0.authentication.result.DatabaseUser; |
33 | 32 | import com.auth0.authentication.result.Delegation; |
34 | 33 | import com.auth0.authentication.result.UserProfile; |
35 | | -import com.auth0.request.ParameterizableRequest; |
36 | 34 | import com.auth0.util.AuthenticationAPI; |
37 | 35 | import com.auth0.util.MockBaseCallback; |
38 | 36 | import com.fasterxml.jackson.core.type.TypeReference; |
|
50 | 48 | import static com.auth0.util.AuthenticationAPI.ID_TOKEN; |
51 | 49 | import static com.auth0.util.AuthenticationAPI.REFRESH_TOKEN; |
52 | 50 | import static com.auth0.util.CallbackMatcher.hasNoError; |
53 | | -import static com.auth0.util.CallbackMatcher.hasNoPayloadOfType; |
54 | 51 | import static com.auth0.util.CallbackMatcher.hasPayload; |
55 | 52 | import static com.auth0.util.CallbackMatcher.hasPayloadOfType; |
56 | 53 | import static org.hamcrest.Matchers.equalTo; |
@@ -769,7 +766,7 @@ public void shouldGetNewIdTokenWithRefreshTokenSync() throws Exception { |
769 | 766 |
|
770 | 767 | assertThat(delegation, is(notNullValue())); |
771 | 768 | } |
772 | | - |
| 769 | + |
773 | 770 | @Test |
774 | 771 | public void shouldUnlinkAccount() throws Exception { |
775 | 772 | mockAPI.willReturnSuccessfulUnlinkAccount(); |
@@ -1173,7 +1170,29 @@ public void shouldFetchProfileAfterLoginRequest() throws Exception { |
1173 | 1170 | assertThat(secondRequest.getPath(), equalTo("/tokeninfo")); |
1174 | 1171 |
|
1175 | 1172 | assertThat(callback, hasPayloadOfType(Authentication.class)); |
| 1173 | + } |
| 1174 | + |
| 1175 | + @Test |
| 1176 | + public void shouldGetOAuthToken() throws Exception { |
| 1177 | + mockAPI |
| 1178 | + .willReturnAuthorizationCodeInfo() |
| 1179 | + .willReturnTokenInfo(); |
1176 | 1180 |
|
| 1181 | + final MockBaseCallback<Credentials> callback = new MockBaseCallback<>(); |
| 1182 | + client.token("code", AuthenticationAPI.CODE_VERIFIER, AuthenticationAPI.REDIRECT_URI) |
| 1183 | + .start(callback); |
| 1184 | + |
| 1185 | + final RecordedRequest request = mockAPI.takeRequest(); |
| 1186 | + assertThat(request.getPath(), equalTo("/oauth/token")); |
| 1187 | + |
| 1188 | + Map<String, String> body = bodyFromRequest(request); |
| 1189 | + assertThat(body, hasEntry("redirect_uri", AuthenticationAPI.REDIRECT_URI)); |
| 1190 | + assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE)); |
| 1191 | + assertThat(body, hasEntry("client_id", CLIENT_ID)); |
| 1192 | + assertThat(body, hasEntry("code_verifier", AuthenticationAPI.CODE_VERIFIER)); |
| 1193 | + assertThat(body, hasEntry("code", "code")); |
| 1194 | + |
| 1195 | + assertThat(callback, hasPayloadOfType(Credentials.class)); |
1177 | 1196 | } |
1178 | 1197 |
|
1179 | 1198 | private Map<String, String> bodyFromRequest(RecordedRequest request) throws java.io.IOException { |
|
0 commit comments