This package allows you to authorize users through a shared redis
pip install bater-fastapi-auth
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'
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)
from bater_fastapi_auth import UserRedisAuth
@app.get("/")
async def read_root(user=Depends(UserRedisAuth())):
return user.to_dict()