pip install oauthlib
python
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
python
client_id = 'your_client_id'
client_secret = 'your_client_secret'
authorization_url = 'https://example.com/oauth/auth'
token_url = 'https://example.com/oauth/token'
python
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
python
authorization_url, state = oauth.authorization_url(authorization_url, scope=['read', 'write'])
print('Please go to {} and authorize access.'.format(authorization_url))
python
token = oauth.fetch_token(token_url, client_id=client_id, client_secret=client_secret,
authorization_response=redirect_response)