Skip to content

Commit 163445a

Browse files
committed
client_credentials client should not set Authorization header when ClientAuthenticationMethod.POST
Fixes gh-6911
1 parent ab14b57 commit 163445a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClient.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,7 +90,6 @@ public Mono<OAuth2AccessTokenResponse> getTokenResponse(OAuth2ClientCredentialsG
9090
private Consumer<HttpHeaders> headers(ClientRegistration clientRegistration) {
9191
return headers -> {
9292
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
93-
headers.setBasicAuth(clientRegistration.getClientId(), clientRegistration.getClientSecret());
9493
if (ClientAuthenticationMethod.BASIC.equals(clientRegistration.getClientAuthenticationMethod())) {
9594
headers.setBasicAuth(clientRegistration.getClientId(), clientRegistration.getClientSecret());
9695
}

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClientTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -95,9 +95,11 @@ public void getTokenResponseWhenPostThenSuccess() throws Exception {
9595
OAuth2ClientCredentialsGrantRequest request = new OAuth2ClientCredentialsGrantRequest(registration);
9696

9797
OAuth2AccessTokenResponse response = this.client.getTokenResponse(request).block();
98-
String body = this.server.takeRequest().getUtf8Body();
98+
RecordedRequest actualRequest = this.server.takeRequest();
99+
String body = actualRequest.getUtf8Body();
99100

100101
assertThat(response.getAccessToken()).isNotNull();
102+
assertThat(actualRequest.getHeader(HttpHeaders.AUTHORIZATION)).isNull();
101103
assertThat(body).isEqualTo("grant_type=client_credentials&scope=read%3Auser&client_id=client-id&client_secret=client-secret");
102104
}
103105

0 commit comments

Comments
 (0)