authx icon indicating copy to clipboard operation
authx copied to clipboard

Failed to import RedisCacheBackend and JWTBackend class from authx. Version 0.4.0

Open r-scheele opened this issue 3 years ago • 3 comments

First Check

  • [X] I added a very descriptive title to this issue.
  • [X] I already read and followed all the tutorial in the docs and didn't find an answer.
  • [X] I already checked if it is not related to AuthX but to Pydantic.
  • [X] I already checked if it is not related to AuthX but to FastAPI.

Example Code

from authx import RedisCacheBackend, JWTBackend, RedisBackend
from fastapi import Depends, FastAPI
from fastapi.security import HTTPBearer
from starlette.config import Config

app = FastAPI(
    title="AuthX",
    description="AuthX authentication system for fastapi.",
    version="0.1.0",
)

config = Config(".env")

SecurityConfig = JWTBackend(
    cache_backend=RedisBackend,
    private_key=config("PRIVATE_KEY", default="private_key"),
    public_key=config("PUBLIC_KEY", default="public_key"),
    access_expiration=3600,
    refresh_expiration=3600
)

oauth_token_scheme = HTTPBearer()


# app.include_router(starlette_app.router) # pygeoapi

# Set Anonymous User
@app.get("/anonym")
def anonym_test():
    pass


# Set Authenticated User
@app.get("/user")
async def user_test(token=Depends(oauth_token_scheme)):
    is_verified = await SecurityConfig.decode_token(token)
    print(is_verified)
    pass

Description

as specified in the documentation for jwt implementation https://authx.yezz.codes/configuration/security/jwt/ , from authx import RedisCacheBackend, JWTBackend should not return an error. as shown below Screenshot from 2022-04-02 15-06-33

  • i want to use JWTBackend to verify token using FastAPI dependency injection. a token should be passed to the swaggerUI docs from fastapi. and should be accessible via the oauth_token_scheme.
  • is_verified should return a boolean showing the verification state of the token, returns None instead of a boolean

Suspected problem RedisCacheBackend is not an exported class from the module - not part of the module, but that is what was shown according to the documentation. using RedisBackend(this is exported from the module) instead, returns TypeError `Expected Type 'RedisBackend', got Type[RedisBackend] instead. in the JWTBackend class

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.75.1

Python Version

python 3.8.10

Additional Context

No response

r-scheele avatar Apr 04 '22 14:04 r-scheele

could you check this https://authx.yezz.codes/configuration/cache/ cause we setup redis in this way and you need to add first the link before that

yezz123 avatar Apr 06 '22 13:04 yezz123

could you check this https://authx.yezz.codes/configuration/cache/ cause we setup redis in this way and you need to add first the link before that

i'm having trouble setting up openid connect, the tutorial is not well explained. can you give me directives?? please

r-scheele avatar Apr 08 '22 11:04 r-scheele

Hello @r-scheele can you please checkout using HTTPCacheBackend https://github.com/yezz123/authx/blob/33bd6100f0f3e261de58e683e788352e1233b057/authx/cache/backend.py#L11

yezz123 avatar Sep 04 '22 03:09 yezz123