OAuth Clients

This part of the documentation contains information on the client parts. Authlib provides many frameworks integrations, including:

  • The famous Python Requests
  • A next generation HTTP client for Python: httpx
  • Flask web framework integration
  • Django web framework integration
  • Starlette web framework integration
  • FastAPI web framework integration

In order to use Authlib client, you have to install each library yourself. For example, you want to use requests OAuth clients:

$ pip install Authlib requests

For instance, you want to use httpx OAuth clients:

$ pip install -U Authlib httpx

Here is a simple overview of Flask OAuth client:

from flask import Flask, jsonify
from authlib.integrations.flask_client import OAuth

app = Flask(__name__)
oauth = OAuth(app)
github = oauth.register('github', {...})

def login():
    redirect_uri = url_for('authorize', _external=True)
    return github.authorize_redirect(redirect_uri)

def authorize():
    token = github.authorize_access_token()
    # you can save the token into database
    profile = github.get('/user', token=token)
    return jsonify(profile)

Follow the documentation below to find out more in detail.