-
Notifications
You must be signed in to change notification settings - Fork 6.1k
URL encode client credentials #9791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @sjohnr. Please see review comments.
.../security/oauth2/client/endpoint/AbstractOAuth2AuthorizationGrantRequestEntityConverter.java
Outdated
Show resolved
Hide resolved
...ecurity/oauth2/client/endpoint/AbstractWebClientReactiveOAuth2AccessTokenResponseClient.java
Outdated
Show resolved
Hide resolved
...ecurity/oauth2/client/endpoint/AbstractWebClientReactiveOAuth2AccessTokenResponseClient.java
Outdated
Show resolved
Hide resolved
...ecurity/oauth2/client/endpoint/AbstractWebClientReactiveOAuth2AccessTokenResponseClient.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @sjohnr. Please apply the updates as per review and then go ahead and merge / backport.
Also, please update the commit comment - remove "if enabled"
...ecurity/oauth2/client/endpoint/AbstractWebClientReactiveOAuth2AccessTokenResponseClient.java
Outdated
Show resolved
Hide resolved
...ingframework/security/oauth2/client/endpoint/OAuth2AuthorizationGrantRequestEntityUtils.java
Outdated
Show resolved
Hide resolved
...security/oauth2/client/endpoint/OAuth2ClientCredentialsGrantRequestEntityConverterTests.java
Outdated
Show resolved
Hide resolved
...urity/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClientTests.java
Outdated
Show resolved
Hide resolved
assertThat(headers.getAccept()).contains(MediaType.APPLICATION_JSON_UTF8); | ||
assertThat(headers.getContentType()) | ||
.isEqualTo(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8")); | ||
String urlEncodedClientCredential = URLEncoder.encode(clientCredentialWithAnsiKeyboardSpecialCharacters, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjohnr Rather than compare it to exactly the same code, actually specify the expected encoded version. e.g. with the case from the RFC:
assertEquals("+%25%26%2B%C2%A3%E2%82%AC", encodeClientCredential(" %&+£€"));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OrangeDog that's a good idea too. However, instead of testing the private method, we could probably test the end result with hard-coded characters. Would you be interested in submitting a PR with an additional test using characters like those (not from the ansi keyboard, as mine was), and asserting like:
assertThat(actualRequest.getHeader(HttpHeaders.AUTHORIZATION)).isEqualTo("Basic <hard-coded encoded credentials here>");
Note: I was mostly concerned with using the test case to ensure that the code complied with the spec, not ensuring specific characters are encoded correctly with Java's encoding mechanism, hence re-using the URLEncoder
class.
Closes gh-9610