pediot commited on
Commit
df66e23
·
1 Parent(s): 63bc8cc

implement verify_token

Browse files
Files changed (1) hide show
  1. src/auth.py +17 -0
src/auth.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import HTTPException, Security
2
+ from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
3
+ from decouple import config
4
+
5
+
6
+ API_TOKEN = config("API_TOKEN")
7
+ security = HTTPBearer()
8
+
9
+
10
+ def verify_token(credentials: HTTPAuthorizationCredentials = Security(security)):
11
+ if credentials.credentials != API_TOKEN:
12
+ raise HTTPException(
13
+ status_code=401,
14
+ detail="Invalid authentication credentials",
15
+ headers={"WWW-Authenticate": "Bearer"},
16
+ )
17
+ return credentials.credentials