Skip to content

URL encode client credentials#9791

Merged
sjohnr merged 1 commit intospring-projects:mainfrom
sjohnr:gh-9610
Jun 1, 2021
Merged

URL encode client credentials#9791
sjohnr merged 1 commit intospring-projects:mainfrom
sjohnr:gh-9610

Conversation

@sjohnr
Copy link
Copy Markdown
Contributor

@sjohnr sjohnr commented May 24, 2021

Closes gh-9610

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 24, 2021
@sjohnr sjohnr added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 24, 2021
@jgrandja jgrandja added this to the 5.5.1 milestone May 25, 2021
Copy link
Copy Markdown
Contributor

@jgrandja jgrandja left a 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.

Copy link
Copy Markdown
Contributor

@jgrandja jgrandja left a 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"

@sjohnr sjohnr changed the title URL encode client credentials if enabled URL encode client credentials Jun 1, 2021
@sjohnr sjohnr merged commit ac9b137 into spring-projects:main Jun 1, 2021
@sjohnr sjohnr deleted the gh-9610 branch June 1, 2021 17:57
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,
Copy link
Copy Markdown
Contributor

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(" %&+£€"));

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client credentials not correctly encoded in Basic Auth

4 participants