Skip to main content

Python SDK for the Authlib

Project description

AuthLib

A Python authentication library that provides JWT, OAuth2, and API token authentication with PostgreSQL backend.

Table of Contents

Installation

pip install -e .

Quick Start

from flask import Flask
from authlib import AuthManager

app = Flask(__name__)

auth = AuthManager(
    app=app,
    db_dsn="postgresql://user:pass@localhost/dbname",
    jwt_secret="your-secret-key",
    oauth_config={
        "google": {
            "client_id": "your-client-id",
            "client_secret": "your-client-secret"
        }
    }
)

@app.route("/protected")
@auth.require_auth(roles=["admin"])
def protected_route():
    return "Protected content"

Configuration

Required Parameters

  • app: Flask application instance
  • db_dsn: PostgreSQL connection string
  • jwt_secret: Secret key for JWT signing

Optional Parameters

  • oauth_config: Dictionary of OAuth provider configurations
  • token_expiry: JWT token expiry time in seconds (default: 3600)
  • refresh_token_expiry: Refresh token expiry time in seconds (default: 2592000)

API Endpoints

Authentication

  • POST /v1/users/login - Login with username/password
  • POST /v1/users/login/oauth - Get OAuth redirect URL
  • GET /v1/users/login/oauth2callback - OAuth callback
  • POST /v1/users/token-refresh - Refresh JWT token

User Management

  • POST /v1/users/register - Register new user
  • GET /v1/users/login/profile - Get user profile
  • GET /v1/users/roles - Get available roles

API Tokens

  • POST /v1/users/{user}/api-tokens - Create API token
  • GET /v1/users/{user}/api-tokens - List API tokens
  • DELETE /v1/users/{user}/api-tokens/{token_id} - Delete API token

Development

Setup

  1. Clone the repository
  2. Create virtual environment:
python -m venv venv
venv\Scripts\activate
  1. Install dependencies:
pip install -e ".[dev]"

Database Setup

createdb authlib
python -m authlib.cli db init

Running Tests

pytest

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

the37lab_authlib-0.1.1749279172.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

the37lab_authlib-0.1.1749279172-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file the37lab_authlib-0.1.1749279172.tar.gz.

File metadata

File hashes

Hashes for the37lab_authlib-0.1.1749279172.tar.gz
Algorithm Hash digest
SHA256 6ea253c2b6051b5101a96735a3de0b3fc3c5a756e1c8f0ef75e377822708a347
MD5 d8d33e7def5c0701e2dbc4f12ac2a372
BLAKE2b-256 7f511791c2fa74458013c402b5ac46a5d6af9b98136e55da72ca5261e19cdb68

See more details on using hashes here.

File details

Details for the file the37lab_authlib-0.1.1749279172-py3-none-any.whl.

File metadata

File hashes

Hashes for the37lab_authlib-0.1.1749279172-py3-none-any.whl
Algorithm Hash digest
SHA256 5071fb9b39943d7a6d42e42b2c6a2951f8abe03483676e609db38bb026ea6862
MD5 2d2c3d8eabe901ce9d51b4a07f940f49
BLAKE2b-256 ead78aca6fd731b8c6c4345ed67b41974675bbe1c5b69171fd7b3f5a383340fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page