Gregniuki commited on
Commit
7c9ef15
1 Parent(s): 9dfcf55

Update auth.py

Browse files
Files changed (1) hide show
  1. auth.py +10 -0
auth.py CHANGED
@@ -19,6 +19,16 @@ class AuthViews:
19
  self.SECRET_KEY = "your-secret-key" # Replace with your actual secret key
20
  self.ALGORITHM = "HS256"
21
  self.ACCESS_TOKEN_EXPIRE_MINUTES = 30
 
 
 
 
 
 
 
 
 
 
22
  # User model
23
  class UserCreate(BaseModel):
24
  username: str
 
19
  self.SECRET_KEY = "your-secret-key" # Replace with your actual secret key
20
  self.ALGORITHM = "HS256"
21
  self.ACCESS_TOKEN_EXPIRE_MINUTES = 30
22
+ def verify_token(token: str = Depends(oauth2_scheme)):
23
+ try:
24
+ payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
25
+ return payload.get("sub")
26
+ except JWTError:
27
+ raise HTTPException(
28
+ status_code=status.HTTP_401_UNAUTHORIZED,
29
+ detail="Could not validate credentials",
30
+ headers={"WWW-Authenticate": "Bearer"},
31
+ )
32
  # User model
33
  class UserCreate(BaseModel):
34
  username: str