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 instancedb_dsn: PostgreSQL connection stringjwt_secret: Secret key for JWT signing
Optional Parameters
oauth_config: Dictionary of OAuth provider configurationstoken_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/passwordPOST /v1/users/login/oauth- Get OAuth redirect URLGET /v1/users/login/oauth2callback- OAuth callbackPOST /v1/users/token-refresh- Refresh JWT token
User Management
POST /v1/users/register- Register new userGET /v1/users/login/profile- Get user profileGET /v1/users/roles- Get available roles
API Tokens
POST /v1/users/{user}/api-tokens- Create API tokenGET /v1/users/{user}/api-tokens- List API tokensDELETE /v1/users/{user}/api-tokens/{token_id}- Delete API token
Development
Setup
- Clone the repository
- Create virtual environment:
python -m venv venv
venv\Scripts\activate
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file the37lab_authlib-0.1.1749279322.tar.gz.
File metadata
- Download URL: the37lab_authlib-0.1.1749279322.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42c9805830759e16081fe2fefa2bc84a5198ef0a2059b648d25aebc75b78f7fb
|
|
| MD5 |
848cb51d61314db02ba38649c09b06b5
|
|
| BLAKE2b-256 |
3868840d56b92734eb3ef3ed78236b2a7c042dc6ede967bbcc6072c407ba2df1
|
File details
Details for the file the37lab_authlib-0.1.1749279322-py3-none-any.whl.
File metadata
- Download URL: the37lab_authlib-0.1.1749279322-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d1c0ffa1f73b35149d8c2b41bcf185e6887eb168168c8b9f80c4e98accfbcad
|
|
| MD5 |
2c3a6a1c022d1fe3f5150804e54a8f88
|
|
| BLAKE2b-256 |
577e53e7c06e7d18ca5a8d12495abce3f53bb4fdf5339424dfe91e25103367ef
|