Skip to main content

FastAPI simple authentication

Project description

FastAPI Simple Auth

Documentation Status

  • 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
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}"

login screenshot

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

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


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.9.tar.gz (66.0 kB view details)

Uploaded Source

Built Distribution

fastapi_simple_auth-0.0.9-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_simple_auth-0.0.9.tar.gz.

File metadata

  • Download URL: fastapi_simple_auth-0.0.9.tar.gz
  • Upload date:
  • Size: 66.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for fastapi_simple_auth-0.0.9.tar.gz
Algorithm Hash digest
SHA256 5efa819a793db4f7c3c30964c5453564b76fc7ae4ffb78cc9af6aee25ecff9f9
MD5 8729200e405a3f9045d2e615694fa14b
BLAKE2b-256 bfb5e6e96744fce350887feebdaaf4f2d0c835dfc63338560ce54d5c35f6d7ea

See more details on using hashes here.

File details

Details for the file fastapi_simple_auth-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_simple_auth-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 92f2898839bbb9e56496d5e9d3800d8463ef6251f03a3c562cef053c6a48702c
MD5 7ff631a728ad93a5b5d1ce4ff5fd57d3
BLAKE2b-256 45eb9788109053a6608b71bd688149625925af24df1e07d6ebdfd6ffea38a519

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page