Spaces:
Sleeping
Sleeping
File size: 957 Bytes
a65f83d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from fastapi import APIRouter, Form, Request,Depends,HTTPException
from service import ChatService
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from request import RequestChat
from typing import Optional
from fastapi.requests import Request
router = APIRouter()
class JWTBearer(HTTPBearer):
def __init__(self, auto_error: bool = True):
super(JWTBearer, self).__init__(auto_error=auto_error)
async def __call__(self, request: Request):
credentials: HTTPAuthorizationCredentials = await super(JWTBearer, self).__call__(request)
if credentials:
if credentials.scheme != "Bearer":
raise HTTPException(status_code=401, detail="Invalid authentication scheme.")
return credentials.credentials
else:
raise HTTPException(status_code=401, detail="Invalid authorization code.")
jwt_bearer = JWTBearer()
import decode_token |