19 lines
522 B
Python
19 lines
522 B
Python
import jwt
|
|
from fastapi import Header, status, HTTPException
|
|
|
|
from backend.code.services.token import TokenService
|
|
|
|
class PrivateMiddleware:
|
|
def __init__(self):
|
|
self._tokenService = TokenService()
|
|
|
|
def HasToken(self, token: str = Header(...)):
|
|
if token is None:
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
|
|
|
if self._tokenService.ValidateToken(token) == False:
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
|
|
|
return token
|
|
|
|
|