Description
Summary
The error description for the insufficient_scope case in BearerTokenAccessDeniedHandler assumes that the denial is caused by an insufficient scope, while it could have many other causes. It is misleading and should be reworded.
Actual Behavior
The error description in org.springframework.security.oauth2.server.resource.web.access.BearerTokenAccessDeniedHandler
for error code insufficient_scope
states that "The token provided has insufficient scope [%s] for this request".
Expected Behavior
RFC 6750 describes this error code with :
The request requires higher privileges than provided by the access token. The resource server SHOULD respond with the HTTP 403 (Forbidden) status code and MAY include the "scope" attribute with the scope necessary to access the protected resource.
An implementation could grant other authorities based on other claims from the token, or from any other source. Access could be denied because of insufficient role, origin... or any other insufficient privilege. Thus, the error description should not assume that the scope is always insufficient.
It could be reworded as : "The token provided has insufficient privileges for this request". This would fix #6280 by the way.
Configuration
Not applicable.
Version
spring-security-oauth2-resource-server-5.1.5.RELEASE