Skip to main content

OAuthLib

OAuthLib - Python Framework for OAuth1 & OAuth2

A generic, spec-compliant, thorough implementation of the OAuth request-signing logic

-- oauthlib/oauthlib

Code snippets

You might be more interested in using requests which has OAuthLib powered OAuth support provided by the requests-oauthlib library.

from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session

session = OAuth2Session(
client=BackendApplicationClient(client_id=CLIENT_ID),
auto_refresh_url=TOKEN_URL,
auto_refresh_kwargs={
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
},
token_updater=lambda t: t,
)
session.fetch_token(
token_url=TOKEN_URL,
client_secret=CLIENT_SECRET,
include_client_id=True,
)