Barter authentication package for FastApi
Project description
Barter authentication package
This package allows you to authorize users through a shared redis
Install package
pip install bater-fastapi-auth
Define env variables
REDIS_AUTH_ACCESS_PREFIX
default ''REDIS_AUTH_DB
default 0REDIS_AUTH_HOST
default 127.0.0.1REDIS_AUTH_PORT
default 6379REDIS_AUTH_PASSWORD
default NoneREDIS_AUTH_TOKEN_STORAGE
default 'headers' should be 'cookies'
Define startapp and shutdown logic
from contextlib import asynccontextmanager
from fastapi import FastAPI
from src.bater_fastapi_auth import token_config
from bater_fastapi_auth.providers import RedisSingleton
@asynccontextmanager
async def lifespan(app: FastAPI):
RedisSingleton.init_redis(
token_config.HOST,
token_config.PORT,
token_config.DB,
token_config.PASSWORD
)
yield
await RedisSingleton().close()
app = FastAPI(lifespan=lifespan)
Use in view
from bater_fastapi_auth import UserRedisAuth
@app.get("/")
async def read_root(user=Depends(UserRedisAuth())):
return user.to_dict()
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
Built Distribution
File details
Details for the file barter_fastapi_auth-0.1.1.tar.gz
.
File metadata
- Download URL: barter_fastapi_auth-0.1.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d7d69eaf453218e0131b173fb752afca00abf30c68dac26fb3405caebe81116 |
|
MD5 | d2ada4666707aea2c58ef529c6410d8b |
|
BLAKE2b-256 | dd5db27bc97916dd4b2e3bbb0f853f2f5f7337893f13409568ce58277df23267 |
File details
Details for the file barter_fastapi_auth-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: barter_fastapi_auth-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ea668425c224c5d5edafa6f033681a82408441ba06cd651f2867c1f182ba091 |
|
MD5 | c911b987de0cd661f8ffe71810776478 |
|
BLAKE2b-256 | eeba37add2bb6544bcb6f049592a9705161d3e570b5b7103da07556d6ef65f07 |