Skip to main content

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 0
  • REDIS_AUTH_HOST default 127.0.0.1
  • REDIS_AUTH_PORT default 6379
  • REDIS_AUTH_PASSWORD default None
  • REDIS_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

barter_fastapi_auth-0.1.1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

barter_fastapi_auth-0.1.1-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

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