这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/lib/auth/prisma.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from fastapi import HTTPException, Request
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

from app.lib.prisma import prisma

jwtSecret = config("JWT_SECRET")


Expand Down Expand Up @@ -51,17 +53,25 @@ async def __call__(self, request: Request):
credentials: HTTPAuthorizationCredentials = await super(
JWTBearer, self
).__call__(request)

if credentials:
if not credentials.scheme == "Bearer":
raise HTTPException(
status_code=403, detail="Invalid authentication scheme."
status_code=403, detail="Invalid token or expired token."
)

if not self.verify_jwt(credentials.credentials):
raise HTTPException(
status_code=403, detail="Invalid token or expired token."
tokens_data = prisma.apitoken.find_first(
where={"token": credentials.credentials}
)

if not tokens_data:
raise HTTPException(
status_code=403, detail="Invalid token or expired token."
)

return signJWT(tokens_data.userId)

return credentials.credentials

else:
Expand Down