-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Allow configuring oauth2ResourceServer() with custom provider #6629
Comments
@OrangeDog, thanks for the report! Can you describe a bit more what you are trying to accomplish? Also, feel free to keep track of #6563, which adds an |
I want everything that it sets up (bearer token filter, endpoint, error handler) except for JWT. The only way to do it is to scrap the whole configurer and do everything manually. It would be easily solved if it just didn't throw the |
What token format are you using for your bearer token? If it's neither opaque nor JWT, then I wonder if what you are building is a Resource Server. One thing that might work is to introduce something like the following: http
.oauth2ResourceServer()
.jwt()
.authenticationManager(new MyCustomAuthenticationManager()) And the same for Then, you can pick whichever semantics - local or remote - best matches your situation. |
Why do it like that when neither JWT nor a whole
|
I think you hit here on some API complexity that Spring Security doesn't need. Why have both Given the example above, if you need to use a provider instead, you could do: http
.oauth2ResourceServer()
.jwt()
.authenticationManager(provider()::authenticate) Is that unreasonable? If so, help me understand your situation better. UPDATE: Really, though, I'm curious why you need an
The reason It wouldn't be very secure for the DSL to give the impression that you're getting all the security benefits of OAuth 2.0 Resource Server when you really aren't.
I think some good questions to ask are: Is the application a Resource Server? And if so, what token format does it use? I'd say that if it's neither JWT nor Opaque token, then it's not a Resource Server. Instead, it's a server that uses the And if that's what you need to configure, then Spring Security makes that entirely possible with relatively little code, there's just not a specialized DSL for that setup. If what I've said above sounds unreasonable, maybe a boarder picture would help me out. Have I missed something about your situation? |
Because that's how your code works. The configurer calls There is no
Nothing in OAuth2 requires a Bearer Token to have any particular implementation, and a bearer token is by definition opaque. Neither does anything require a Resource Server to use a specific token implementation. Moreover, the implementation of "Opaque" tokens currently in master is very narrow, mandating that the token be used in an HTTP request that returns its details. I just want short, stateful tokens, but I also want a full resource server with everything else that
As far as I can see it is perfectly secure to just skip the JWT configuration. This results in it being impossible to authenticate any bearer tokens. Unless for example you've added a different |
Now I've started using |
@OrangeDog could you provide a sample of what you can't do without copying
You and I are both proposing ways to change the code from its current state. My question is in the context of our conversation here, which is where you'd provide an http
.oauth2ResourceServer()
.jwt()
.authenticationManager(...) or, as you said, if your token is opaque, then http
.oauth2ResourceServer()
.opaqueToken()
.authenticationManager(...) Would you still need an
I'm open to discussion on this, too, but let's do that in another ticket just to keep this conversation focused. Since 5.2 is not yet released, there's a lot of breathing room, and it's community feedback that's going to make sure these features address real needs. |
I've just stopped using this completely now. The resource server configuration in spring-security-oauth2 provides far more functionality, far more flexibly, so I'm using that. |
@OrangeDog I'm glad that you found something that addresses your needs. Sorry that we couldn't find a solution together. Just in case it's not clear, note that |
I see. I would suggest you ensure there is equivalent functionality (or at least the extension points) in core before doing that. So far (on the resource server side) I've found the On the auth server side I'm using most features including custom approvals, persistent and revocable refresh tokens, different stores for different token types. User authentication is via other providers (currently SAML) so password grants are not available to me, which complicates matters. |
Yes, we'll officially deprecate once we have feature parity. The extension points may change, of course. Thanks for the feedback about what you are using in Some quick notes about that:
These are both possible in the new JWT support via a custom authentication token. Opaque Token support for the same is coming in 5.2. In http
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(this::convertJwtToCustomAuthenticationToken) If an At this point, I'll close this ticket, but feel free to reopen if you'd like to further discuss ways to provide a custom http
.oauth2ResourceServer()
.jwt()
.authenticationManager(...) which I'm still thinking is quite similar to what you were originally thinking (allowing for a custom authentication provider) aside from the discussion about exceptions. |
At the moment if you do not configure
jwt()
(oropaqueToken()
on the master branch) the configurer will throw anIllegalStateException
.However, all that is needed to support another format is to add an
AuthenticationProvider
supportingBearerTokenAuthenticationToken
. Because the configurer throws, it forces you to manually configure everything else yourself as well.Instead, it should either allow setting a specific provider, or warn instead of throwing if it cannot configure one.
Related: #6209
The text was updated successfully, but these errors were encountered: