Accept: application/json header
Visuals3D opened this issue · 2 comments
requests_oauth2client
version: v1.3.0
Description
The request client session is used in multiple functions within the client.py with the expectation to recieve json formated responses from the oauth2 endpoint. For some OAuth endpoints the default response type is not application/json
What I Did
The header can simply be added when calling the authorization_code function like this:
token = oauth2client.authorization_code(code=code, headers={"Accept": "application/json"})
The header can also be set from the outside for the whole session like this:
oauth2client = OAuth2Client(
client_id=client_id,
client_secret=client_secret
)
oauth2client.session.headers["Accept"] = "application/json"
But the client implementation can't handle something else than json responses so I modified the client.py file to add the Accept: application/json header to the request session in line 181 used trough out the client.py implementation
self.session = session or requests.Session()
self.session.headers["Accept"] = "application/json" # Multiple client functions depend on responses being in json format. Therefore it should be set in the header
Sadly i have no permission to create a branch and PR to fix it. Maybe you agree and want to move this change into the client.py implementation or implement logic to react to other response types. For example the types that GitHub itself provides for oidc: https://docs.github.com/en/enterprise-server@3.8/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#2-users-are-redirected-back-to-your-site-by-github
Thanks for the suggestion. Indeed, I don't think it would hurt to add an explicit Accept: application/json
header by default to requests to the token endpoint. I'll see what I can do.