Skip to content

Easy and secure JWTs for FastAPI that is indifferent to your data model

License

Notifications You must be signed in to change notification settings

davideasaf/fast-legion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fast-Legion

A JWT Security Bundle that let's you choose your favorite data layer for the FastAPI framework.

Key features:

  • Fast First: Fast Legion was built with FastAPI in mind first. That means typing, DI, docs, and flexibilty are key.
  • Simple to Integrate: Provide a Config and some function wrappers around your data layer and you've got a modern JWT secure API.
  • Zero Favorites: FastAPI doesn't pick favorites and neither does Fast Legion. Bring your own data layer such as a relational or NoSQL database. As long as you provide users, Fast Legion is happy to secure it.
  • Secure
    • Hashes passwords and exposes a hashing function for you to use outside of your app
    • Verify plain text passwords against your apps hashed passwords
    • Generate OAuth2.0 compliant authorization tokens on successful user login
    • Set a custom expiration for your tokens
    • Get the full user injected into your route when you need it

Requirements

Python 3.6+

Installation

$ pip install fast-legion

---> 100%

Quick Start

Fast legion is setup in 1 step:

from fast_legion import (
    Legion,
    LegionConfig,
)

api = FastAPI(title="Basic API Demo for Fast Legion")

Legion(
    api,
    lookup_by_username=lookup_by_username,
    lookup_by_id=lookup_by_id,
    get_user_rolenames=get_user_rolenames,
    get_user_password_hash=get_user_password_hash,
    get_user_id=get_user_id,
    config=LegionConfig(),
)

Parameters

  1. lookup_by_username: function to return the user given a username
  2. lookup_by_id: function to return the user given an id
  3. get_user_rolenames: function that takes a user and returns list of string usernames
  4. get_user_password_hash: function that takes a user and returns their hashed password
  5. get_user_id: function: that takes a user and returns their id
  6. config: Pydantic Model imported from Fast Legion. Contains all the configurations for Fast Legion (the above shows Fast Legion using all defaults)

for the function signatures, refer to the Minimal Example

Examples

  1. Minimal Example
  2. SQLAlchemy Example

API Docs Output

Example Docs

License

This project is licensed under the terms of the MIT license.

About

Easy and secure JWTs for FastAPI that is indifferent to your data model

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages