Coverage for auth\authenticate.py: 89%
9 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:00 +0800
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:00 +0800
1from auth.jwt_handler import verify_access_token
2from fastapi import Depends, HTTPException, status
3from fastapi.security import OAuth2PasswordBearer
5oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/user/signin")
8async def authenticate(token: str = Depends(oauth2_scheme)) -> str:
9 if not token:
10 raise HTTPException(
11 status_code=status.HTTP_403_FORBIDDEN,
12 detail="Sign in for access"
13 )
15 decoded_token = await verify_access_token(token)
16 return decoded_token["user"]