Simple Authentication Library for FastAPI
Project description
Fast Auth Tools (for FastAPI)
Adds oauth2 authentication to a FastApi app with a single function
Install
pip install fast-auth-tools
Create User DB
python -m fast_auth.create_sqlite_db ./my_user_db.sqlite3
db path argument is optional and will default to .../site_packages/fast_auth/users.sqlite3
Example
import os
from fastapi import FastAPI, Depends
from fast_auth import fast_auth, logged_in_user, User
from fast_auth import settings as auth_settings
auth_settings.user_db_path = "./my_user_db.sqlite3" # if the path was changed
auth_settings.secret_key = os.getenv("FAST_AUTH_SECRET_KEY")
auth_settings.cors_origins = ["myapp.com", "my-test-server.com"]
app = FastAPI()
fast_auth(app)
# Example authenticated routes:
@app.get("/secure/get/", dependencies=[Depends(logged_in_user)])
async def must_be_logged_in():
return {}
@app.post("/secure/post/")
async def get_user_object(user: User = Depends(logged_in_user)):
print(f"password hash: {user.password}")
return {
"data": f"{user.username} is already logged in"
}
Settings
| name | default | description |
|---|---|---|
| cors_origins | ["*"] | allowed CORS origins |
| secret_key | "SoMeThInG_-sUp3Rs3kREt!!" | the key used to encrypt JWT |
| algorithm | "HS256" | the alogrithm used to encrypt JWT |
| access_token_expire_days | 5 | the maximum number of days JWT will be valid |
| user_db_path | ".../site_packages/fast_auth/users.sqlite3" | the path to the sqlite database that holds username/encrypted password information |
| login_url | "login" | path to POST endpoint accepting username/password form data |
| token_refresh_url | "refresh_token" | path to GET endpoint that takes a valid JWT and returns a new JWT with maximum expiry |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fast_auth_tools-0.2.2.tar.gz
(6.4 kB
view details)
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 fast_auth_tools-0.2.2.tar.gz.
File metadata
- Download URL: fast_auth_tools-0.2.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa9d1cdb685e395fa6294de706d9bf712a0d058dfe4b68b17f5aa97c0f459c87
|
|
| MD5 |
1168bc6553cbf165e1ace62499f1e53c
|
|
| BLAKE2b-256 |
e6537407ce9018de3f2822d5ee1846df8b7eb99d2f725597ba2da1df8f1a70cf
|
File details
Details for the file fast_auth_tools-0.2.2-py3-none-any.whl.
File metadata
- Download URL: fast_auth_tools-0.2.2-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deefb9595a1b419aab9c795a51880cc2d0ba6174c246994158c6e23205553f49
|
|
| MD5 |
522dde9a7c75a16254999460ffe157fc
|
|
| BLAKE2b-256 |
d8463bccb3d85423eef7f97064762c9173213c3ec24335121e113aaa070e09da
|