-
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
Introduce JWT Flow API in Test Support #6634
Comments
Using Missed the part of the spec with the Jwt instance. Will fix that soon. Went further this spec as I propose equivalents for Bearer access-token and OidcId token. All is based on commons I initiated for annotations equivalents (#6557) Branches are ordered as follow (so PRs are streamed as follow):
|
@jgrandja, @rwinch, could you please confirm your intention is not cutting the merges after JWT flow APIs (servlet & reactive)? To me, limiting features to "flow API for Jwt secured @controllers, without scope claim support" is more of a gadget than an "Spring5 OAuth2 unit-test support":
I tried to correct as much as possible before going at see again but am quite unsatisfied with my push:
|
@jzheaux first, please forgive me for my last comment typo, It's you who I intented to ping at first rank as you are the one reviewing the PR. |
There's been some discussion about the contract on #6748, and I'd like to update the ticket here with some changes to the original proposal found in the ticket's description. It will likely be more flexible to separate this.mockMvc.perform(get("/")
.with(jwt()))
.andExcept(status().isOk()); as already stated. Let's also support:
this.mockMvc.perform(get("/")
.with(jwt(jwt -> jwt.claim(SUB, "the-subject"))))
...
this.mockMvc.perform(get("/")
.with(jwt(jwt -> jwt.header("alg", RS256))))
...
this.mockMvc.perform(get("/")
.with(jwt().authorities("SCOPE_message:read")))
...
// or
this.mockMvc.perform(get("/")
.with(jwt(jwt -> jwt.claim("scope", "message:read"))))
...
// or
this.mockMvc.perform(get("/")
.with(jwt().authorities(jwt -> toGrantedAuthorities(jwt))))
... We can easily leverage the output of #6851 to make this a simple introduction of |
In addition to what was written above by @jzheaux (and knowing following are points we do not agree on): Regarding the
Regarding token builders, when there are standard claims (Jwt, Introspection, OpenId, ...), it should expose setters for each. Applications using private claims, can then extend framework builders to support their own claims. So with a Jwt Builder consumer as from @jzheaux sample, this would mean: jwt().token(jwt -> jwt.subject("user").expiresAt(Instant.now)); // etc. "scope" is OAuth2 tokens meta-data (not a claim but part of the successful authorization response for the token). As there is no class I'm aware of in authentication stack that holds both the token and it's meta-data, it would make sens to also expose a method to add well-formatted (conform to the OAuth2 RFC) scope claim to authentication builders: jwt().scopes("message:read", "message:write"); Most of this is more or less implemented there: https://github.com/ch4mpy/spring-addons/tree/master/spring-security-test-oauth2-addons P.S. @jzheaux unfortunately, I'm timed up. I have to go at sea again to reach Panama, might be quite occupied solving formalities to use the canal there and will be at sea for more than a month after before I reach French Polynesia. I think you can modify My repo to make the PR at your wish. You can also copy / paste whatever you like to a new repo, I'd don't really mind being an author, even if I put a lot of energy in this (and time and money...) |
Your contribution is much appreciated, we certainly wouldn't have |
It would be handy in tests to be able to specify a
Jwt
authentication in tests:Some features we should consider:
Jwt
:These would result in the
SecurityContext
containing an instance ofJwtAuthenticationToken
.Also, we should introduce its reactive equivalent.
The text was updated successfully, but these errors were encountered: