You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using latest version of the requests-authlibpackage.
For our authorization server, we added support for audience claim, according RFC 8707. So, basically put, one client can request access to one or many resources by adding the resource parameter in the token request body. When requesting access to many resources, many 'resource' parameters need to be added into the token request rather than a single 'resource' parameter with space-separated resource values (resource URI), as it is done with scope claim.
For instance, for a token request using the client credentials grant (POST request):
The text was updated successfully, but these errors were encountered:
nuxwin
changed the title
BUG - Unable to set multiple 'resource' parameter in token request body, as specified in RFC 8707 : Resource Indicators for OAuth 2.0
BUG - Unable to set multiple 'resource' parameters in token request body, as specified in RFC 8707 : Resource Indicators for OAuth 2.0
Dec 28, 2024
importastfromoauthlib.oauth2importBackendApplicationClientfromrequests_oauthlibimportOAuth2Session# Register a hook to add multiple resource parameters to the token request as per RFC 8707.def_oauth2_resource_indicators_injector(token_url, headers, request_kwargs):
# Modify the resource parameter to be a listif"data"inrequest_kwargsandisinstance(request_kwargs["data"], dict) and"resource"inrequest_kwargs["data"]:
# Convert the string that looks like a list into an actual list using ast.literal_evaltry:
resource_list=ast.literal_eval(request_kwargs["data"]["resource"])
# Ensure it's a list.ifisinstance(resource_list, list):
# Overwrite the resource parameter with the list.request_kwargs["data"]["resource"] =resource_listexcept (ValueError, SyntaxError):
# If conversion fails, leave it as is.passreturntoken_url, headers, request_kwargsoauth_session=OAuth2Session(client=BackendApplicationClient(client_id='abcdefg'))
oauth_session.register_compliance_hook("access_token_request", _oauth2_resource_indicators_injector)
token=oauth_session.fetch_token(
token_url="https://my-oauthorization-server.tld/o/token",
client_id="abcdefg",
client_secret="abcdefgabcdefgabcdefgabcdefg",
resource=[
"https://api1.example.com",
"https://api2.example.com"
],
scope=["read", "write"]
)
Hi,
I'm using latest version of the
requests-authlib
package.For our authorization server, we added support for audience claim, according RFC 8707. So, basically put, one client can request access to one or many resources by adding the
resource
parameter in the token request body. When requesting access to many resources, many 'resource' parameters need to be added into the token request rather than a single 'resource' parameter with space-separated resource values (resource URI), as it is done with scope claim.For instance, for a token request using the client credentials grant (POST request):
The problem is that with your current implementation, resulting Request kwargs are wrong.
resource
parameters through kwargs, as a list:As you can see the list of
resource
parameters is encoded as single string which is wrong.resource
parameters through body:As you can see, only one
resource
parameter is kept which is wrong too.For the record, I tried with the following code:
By passing multiple
resource
parameters in body:By passing multiple
resource
parameters as kwargs:Thank you.
The text was updated successfully, but these errors were encountered: