requests-oauthlib
requests-oauthlib copied to clipboard
fix: explicitly add scope to OAuth2Session.prepare_request_body
The fetch_token function calls the prepare_request_body function. However, it does not pass the scope initialized in the OAuth2Session class constructor. This leads to Missing access token error in cases where the scope is a required parameter. I believe explicitly passing it here makes sense.
This fix may be related to https://github.com/requests/requests-oauthlib/issues/324
Code used to test
import os
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
client_secret = os.environ['CLIENT_SECRET']
client_id = os.environ['CLIENT_ID']
token_url= os.environ['TOKEN_URL']
scope = ['examplescope']
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client, scope=scope)
token = oauth.fetch_token(token_url=token_url, client_id=client_id,
client_secret=client_secret)