|
@@ -115,6 +115,27 @@ public class OAuth2ClientCredentialsGrantTests {
|
|
|
verify(authorizationService).save(any());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void requestWhenTokenRequestPostsClientCredentialsThenTokenResponse() throws Exception {
|
|
|
+ this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
|
|
+
|
|
|
+ RegisteredClient registeredClient = TestRegisteredClients.registeredClient2().build();
|
|
|
+ when(registeredClientRepository.findByClientId(eq(registeredClient.getClientId())))
|
|
|
+ .thenReturn(registeredClient);
|
|
|
+
|
|
|
+ this.mvc.perform(post(OAuth2TokenEndpointFilter.DEFAULT_TOKEN_ENDPOINT_URI)
|
|
|
+ .param(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.CLIENT_CREDENTIALS.getValue())
|
|
|
+ .param(OAuth2ParameterNames.SCOPE, "scope1 scope2")
|
|
|
+ .param(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId())
|
|
|
+ .param(OAuth2ParameterNames.CLIENT_SECRET, registeredClient.getClientSecret()))
|
|
|
+ .andExpect(status().isOk())
|
|
|
+ .andExpect(jsonPath("$.access_token").isNotEmpty())
|
|
|
+ .andExpect(jsonPath("$.scope").value("scope1 scope2"));
|
|
|
+
|
|
|
+ verify(registeredClientRepository).findByClientId(eq(registeredClient.getClientId()));
|
|
|
+ verify(authorizationService).save(any());
|
|
|
+ }
|
|
|
+
|
|
|
private static String encodeBasicAuth(String clientId, String secret) throws Exception {
|
|
|
clientId = URLEncoder.encode(clientId, StandardCharsets.UTF_8.name());
|
|
|
secret = URLEncoder.encode(secret, StandardCharsets.UTF_8.name());
|