FastAPI simple authentication
Project description
FastAPI Simple Auth
- Such a long name! It's hard to type it out.
- Yes, but everything else in this project is simple.
Authentication easy as three lines!
- Import package
- hook to app with
SimpleAuth(app)
- add
user: logged_in_user
to protected view
from fastapi import FastAPI
from fastapi_simple_auth import SimpleAuth, logged_in_user
app = FastAPI()
simpleauth = SimpleAuth(app)
@app.get("/")
async def read_users_me(user: logged_in_user) -> str:
return f"Hello {user.username} {user.uuid}"
Features
- Users are stored in any supported SQLAlchemy database
- Optional email verification
- User creation
- Password recovery
- Profile page with change password, change email
- Custom UI themes!
Install
pip3 install fastapi-simple-auth
# create/edit .env file
vim .env
simpleauth dbupgrade
Write app in app.py
Start:
uvicorn app:app
Usage
This examples uses httpie because it is very good to craft JSON requests.
# register
http POST http://localhost:8000/auth/users/ username=me@example.com password=secret
# simple auth (session)
http -f POST http://localhost:8000/auth/login username=me@example.com password=secret
# get token
http -f POST http://localhost:8000/auth/token username=me@example.com password=secret
Developer cheatsheet
Alembic cheatsheet
alembic revision --autogenerate -m "some desc"
alembic upgrade head
alembic current
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
fastapi_simple_auth-0.0.8.tar.gz
(64.3 kB
view details)
Built Distribution
File details
Details for the file fastapi_simple_auth-0.0.8.tar.gz
.
File metadata
- Download URL: fastapi_simple_auth-0.0.8.tar.gz
- Upload date:
- Size: 64.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e5e79a73f3469cd6ef7c401fad46673292b11142b82fdeba97e1cffbc3d75fc |
|
MD5 | 2bd9f16917750b2d29f1e55fc8e37efe |
|
BLAKE2b-256 | a6ee2a74a059e1edbabbfa6588a7a14ad48a4b5004fbd472aaf7f9353105124e |
File details
Details for the file fastapi_simple_auth-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: fastapi_simple_auth-0.0.8-py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71687f86f9c6c047d693f36a9c0ef8b92b11ff71969da67bc58db70625b375b5 |
|
MD5 | 756e1e342efefcc73e3fd81321f704ea |
|
BLAKE2b-256 | db72893eeba0e484cba83066d2c5a4dae1432347cf83258a1eff4de4091e507d |