Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaroslaff/fastapi-simple-auth
Simple authentication for FastAPI
https://github.com/yaroslaff/fastapi-simple-auth
Last synced: 3 months ago
JSON representation
Simple authentication for FastAPI
- Host: GitHub
- URL: https://github.com/yaroslaff/fastapi-simple-auth
- Owner: yaroslaff
- License: mit
- Created: 2024-02-01T18:06:17.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-15T17:16:04.000Z (5 months ago)
- Last Synced: 2024-10-30T15:13:28.451Z (4 months ago)
- Language: Python
- Homepage:
- Size: 184 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastAPI Simple Auth
[](https://fastapi-simple-auth.readthedocs.io/en/latest/?badge=latest)
- 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!
1. Import package
2. hook to app with `SimpleAuth(app)`
3. add `user: logged_in_user` to protected view~~~python
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 (sqlite3, mysql, ...)
- Optional email verification
- User creation
- Password recovery
- Flexible password strength requirements
- Profile page with change password, change email
- Easy to configure via environment / .env
- Custom UI themes!## Documentation
https://fastapi-simple-auth.readthedocs.io/
## Install
~~~shell
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](http://httpie.io/) because it is very good to craft JSON requests.
~~~
# register
http POST http://localhost:8000/auth/users/ [email protected] password=secret# simple auth (session)
http -f POST http://localhost:8000/auth/login [email protected] password=secret# get token
http -f POST http://localhost:8000/auth/token [email protected] password=secret
~~~## Developer cheatsheet
### Alembic cheatsheet
~~~
alembic revision --autogenerate -m "some desc"
alembic upgrade head
alembic current
~~~