Skip to main content

GSpot authentication package for FastApi

Project description

GSpot authentication package

This package allows you to authorize users through a shared redis

Install package

pip install gspot-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.gspot_fastapi_auth import token_config
from gspot_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 gspot_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

gspot_fastapi_auth-0.0.6.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gspot_fastapi_auth-0.0.6-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file gspot_fastapi_auth-0.0.6.tar.gz.

File metadata

  • Download URL: gspot_fastapi_auth-0.0.6.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for gspot_fastapi_auth-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4f6f72c6375cdcbf05f60e938de4ba875c4d6b03a2d8b0d93e51fe329515aa66
MD5 db7d68597d79afaca1154488ea02c1d5
BLAKE2b-256 51416079191dc4e42cd9f18180379f1452fc9d31522b5718b6eeb12b2b100bcc

See more details on using hashes here.

File details

Details for the file gspot_fastapi_auth-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for gspot_fastapi_auth-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 771642ba79702c47fba7ef848822457916300b6b0ecbe4beab6e66e3733c0437
MD5 daf4a3a38eb390ee77a993c4b8b557be
BLAKE2b-256 4c736bdb719ed36596233e87dfe37c2e9f5c12e6e9cef2dfe93bc9dcdef8c27e

See more details on using hashes here.

Supported by

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