atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

Show better error when an unknown scope is requested #537

Open sirex opened 7 months ago

sirex commented 7 months ago

When I request an unknown scope, for example:

SERVER=:8000
CLIENT=test
SECRET=secret
http \
    -a $CLIENT:$SECRET \
    -f $SERVER/auth/token \
    grant_type=client_credentials \
    scope=unknown_scope

I get following error:

HTTP/1.1 400 Bad Request

{
    "error": "invalid_scope",
    "error_description": "The requested scope is invalid, unknown, or malformed."
}

It would be much more useful, if error message explain, which scope was not recognized.

The error comes from here:

ERROR: Authorization server error: invalid_scope: 
Traceback (most recent call last):
  File "authlib/oauth2/rfc6749/authorization_server.py", line 185, in create_token_response
    grant.validate_token_request()
  File "authlib/oauth2/rfc6749/grants/client_credentials.py", line 72, in validate_token_request
    self.validate_requested_scope(client)
  File "authlib/oauth2/rfc6749/grants/base.py", line 92, in validate_requested_scope
    raise InvalidScopeError(state=self.request.state)
authlib.oauth2.rfc6749.errors.InvalidScopeError: invalid_scope: 
INFO: "POST /auth/token HTTP/1.1" 400 Bad Request

Related