Client¶
Authlib provides OAuth 2.0 client implementations for two distinct use cases:
HTTP Clients — your Python code fetches tokens and calls APIs directly. Suitable for scripts, CLIs, service-to-service communication:
from authlib.integrations.requests_client import OAuth2Session
client = OAuth2Session(client_id, client_secret)
token = client.fetch_token(token_endpoint, ...)
resp = client.get('https://api.example.com/data')
Web Clients — your web application delegates authentication to an OAuth 2.0 provider. Works with any provider: well-known services (GitHub, Google…) or your own authorization server. Integrations for Flask, Django, Starlette and FastAPI:
from authlib.integrations.flask_client import OAuth
oauth = OAuth(app)
github = oauth.register('github', {...})
@app.route('/login')
def login():
return github.authorize_redirect(url_for('authorize', _external=True))
- HTTP Clients
- OAuth 2.0 for Requests
- OAuth 2.0 for HTTPX
- Reference
- OAuth2Session for Authorization Code
- OAuth2Session for Implicit
- OAuth2Session for Password
- OAuth2Session for Client Credentials
- Client Authentication
- Access Protected Resources
- Refresh & Auto Update Token
- Revoke and Introspect Token
- Compliance Fix for non Standard
- OAuth 2 OpenID Connect
- AssertionSession
- Web Clients