chatbot_server / controller /RecommendController.py
kltn21110's picture
Upload 15 files
a65f83d verified
raw
history blame
957 Bytes
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