-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Add support for access token in body parameter as per rfc 6750 Sec. 2.2 #15819
Open
jonah1und1
wants to merge
8
commits into
spring-projects:main
Choose a base branch
from
jonah1und1:gh-15818
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6803ac4
Add support for access token in body parameter as per rfc 6750 Sec. 2.2
jonah1und1 578a559
allow other body params (should've read the whole rfc 6750 doc)
jonah1und1 bbe31b5
Merge branch 'main' into gh-15818
jonah1und1 d14b2c4
make Java 8 compliant
jonah1und1 5e2b304
important import order
jonah1und1 157267a
replace left over vars for Java 8 compliance
jonah1und1 f478022
Merge branch 'main' into gh-15818
jonah1und1 0b7b3ec
Add missing javaDoc
jonah1und1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it be possible to resolve without the creation of
Tuple
s here? It is generally preferred to avoid creation of additional objects when possible (e.g.Stream
) and I thinkTuple
would fall in the same category here. Instead of theTokenSource
, I believeMono#switchIfEmpty
could be used.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.
I am sorry, I fail to see how to resolve this without some kind of information where the token is from, to then check whether it is supported. Could you please give me an hint on how to use
Mono#switchIfEmpty
here?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.
My mistake. Since you're using
Flux.merge()
, it would actually beFlux#switchIfEmpty
.The new
resolveAccessTokenFromBody()
checks aboolean
, method and content-type before returning aMono
. TheresolveAccessTokenFromRequest()
method can be refactored to do the same. In that case,Flux.merge()
will return some number of tokens (0-3) that don't require checking the source again. It would end up looking something like this: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.
Thank you for your answer!
Unfortunately, I think there might be two problems with this approach:
Firstly, if no token can be found the current implementation of
ServerBearerTokenAuthenticationConverter#convert()
returns an empty mono. AninvalidTokenError()
is only raised if the String containing the token is empty, but not if it'snull
.This could be mitigated with relative ease imo, by leaving
convert()
in its current state and replacingswitchIfEmpty()
by a second if-clause inside of.flatMap()
:Secondly, the tests
resolveWhenValidHeaderIsPresentTogetherWithQueryParameterThenAuthenticationExceptionIsThrown()
andresolveWhenQueryParameterHasMultipleAccessTokensThenOAuth2AuthenticationException()
fail because they do not setallowUriQueryParameter
totrue
first. While I am not quite sure about the expected behaviour here and whether addingthis.converter.setAllowUriQueryParameter(true)
to both tests is acceptable, doing so might change the current behaviour.resolveWhenValidQueryParameterIsPresentTogetherWithBodyParameterThenAuthenticationExceptionIsThrown()
, which was added by me, also fails because the query parameter access token is filtered due to thePOST
-request.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.
Hmm, fair point.
Also a fair point. This is unfortunate, because it could be argued that leaving this false implies that such parameters should be ignored. The test and original implementation don't agree though and that makes this tricky. I think this comes down to whether it would be considered a bug to read the token from the request (e.g. query string or body parameters) and validate it when it is not explicitly enabled.
The spec states that
for both body parameters and query string parameters. I don't see anything in the Error Codes section indicating that the request MUST be validated for these problems if the server doesn't support a particular method for resolving the token.
For those reasons, I'm inclined to open an bug to necessitate a change in behavior for both servlet and reactive implementations that would be a precursor to this enhancement. What do you think?
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.
Sorry for the late reply!
Sounds sound to open a dedicated bug ticket for that. Do you want me to implement a PR for that?
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.
@jonah1und1 I opened gh-16038. I think it would be nice to get this fixed in the release this month. Feel free to open a PR if you have availability to work on it, or if you're busy let me know and I can submit a fix.
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.
I created a PR: #16039