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.7.tar.gz
(64.3 kB
view details)
Built Distribution
File details
Details for the file fastapi_simple_auth-0.0.7.tar.gz
.
File metadata
- Download URL: fastapi_simple_auth-0.0.7.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 | 9e684d558a172c27177561f28a8d1fe40f8619ad0e6e88d5e2bcbad35e3bb2b4 |
|
MD5 | 94332ed1264bb9f2baac577e33c4c8ec |
|
BLAKE2b-256 | 60ce9db78ed9109057d01cf07e3fb77d9bda486d3294cc42ed89f1696a585c15 |
File details
Details for the file fastapi_simple_auth-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: fastapi_simple_auth-0.0.7-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 | 21dce7c2bc7017b7dc9d4bf2ca73f19655a02757898de99297a357a406b6500a |
|
MD5 | 31bebb4eba891d8dd1bb379f46a96cd3 |
|
BLAKE2b-256 | b557f6d53a731b21cf40608451938fd69b3f44c97fb057cb02f2cce1f11c3912 |