Skip to content

Commit 38ba70b

Browse files
committed
client_credentials client should not set Authorization header when ClientAuthenticationMethod.POST
Fixes gh-6911
1 parent 6148eef commit 38ba70b

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

Lines changed: 1 addition & 2 deletions
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.
@@ -91,7 +91,6 @@ public Mono<OAuth2AccessTokenResponse> getTokenResponse(OAuth2ClientCredentialsG
9191
private Consumer<HttpHeaders> headers(ClientRegistration clientRegistration) {
9292
return headers -> {
9393
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
94-
headers.setBasicAuth(clientRegistration.getClientId(), clientRegistration.getClientSecret());
9594
if (ClientAuthenticationMethod.BASIC.equals(clientRegistration.getClientAuthenticationMethod())) {
9695
headers.setBasicAuth(clientRegistration.getClientId(), clientRegistration.getClientSecret());
9796
}

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

Lines changed: 4 additions & 2 deletions
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.
@@ -98,9 +98,11 @@ public void getTokenResponseWhenPostThenSuccess() throws Exception {
9898
OAuth2ClientCredentialsGrantRequest request = new OAuth2ClientCredentialsGrantRequest(registration);
9999

100100
OAuth2AccessTokenResponse response = this.client.getTokenResponse(request).block();
101-
String body = this.server.takeRequest().getUtf8Body();
101+
RecordedRequest actualRequest = this.server.takeRequest();
102+
String body = actualRequest.getUtf8Body();
102103

103104
assertThat(response.getAccessToken()).isNotNull();
105+
assertThat(actualRequest.getHeader(HttpHeaders.AUTHORIZATION)).isNull();
104106
assertThat(body).isEqualTo("grant_type=client_credentials&scope=read%3Auser&client_id=client-id&client_secret=client-secret");
105107
}
106108

0 commit comments

Comments
 (0)