We have an application which is using spring-security-oauth2:1.0
. I was trying to change it to a newer version, spring-security-oauth2:2.0.7.RELEASE
. If I don't specify the scope
or If I specify I single scope, the application works fine. I have a problem while requesting multiple scopes like read,write
, which used to work in previous version.
The client I am requesting has all read,write and trust
permissions.
When I was using spring-security-oauth2:1.0
, to get a token I used to do a get call like
http://localhost:8080/oauth/token?grant_type=password&client_id=ws&client_secret=secret&scope=read,write&[email protected]&password=temp123
If you see the scope parameter scope=read,write
, by requesting this way I used to get a token with scope read and write
.
If I try to do the same thing with Oauth2 version 2.0.7.RELEASE
(with a POST
request though), I get Invalid Scope
exception because the tokenRequest
is taking read,write
as a single scope. The client I am requesting has read,write and trust
permissions but read,write
is not one of them.
If I try it with scope=write
or scope=read
, It works fine because read
or write
are part of the client's scope.
If I want to request for multiple scopes in OAuth2 2.0.7.RELEASE
, how do I do that?
OAuth 2.0 was developed by IETF OAuth Working Group and published in October of 2012. It serves as an open authorization protocol for enabling a third party application to get limited access to an HTTP service on behalf of the resource owner.
You don't necessarily need OAuth2 scopes, and you can handle authentication and authorization however you want. But OAuth2 with scopes can be nicely integrated into your API (with OpenAPI) and your API docs.
Spring Security OAuth2 project is currently deprecated and Spring Security team has decided to no longer provide support for authorization servers.
Deprecated. Strategy for extracting an Authorization header from an access token and the request details.
I found the correct way to do this. Instead of a comma separated scopes, you have to use +
to separate scopes.
Ex: read+write
, write+trust
So the following POST
request worked fine.
http://localhost:8080/oauth/token?grant_type=password&client_id=ws&client_secret=secret&scope=read+write&[email protected]&password=temp123
I hope it will help others :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With