Spaces:
Sleeping
Sleeping
Update core/security.py
Browse files- core/security.py +0 -4
core/security.py
CHANGED
|
@@ -20,15 +20,12 @@ oauth2_scheme = OAuth2PasswordBearer(
|
|
| 20 |
# Password hashing context
|
| 21 |
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
| 22 |
|
| 23 |
-
# Hash a plain password
|
| 24 |
def hash_password(password: str) -> str:
|
| 25 |
return pwd_context.hash(password)
|
| 26 |
|
| 27 |
-
# Verify a plain password against the hash
|
| 28 |
def verify_password(plain: str, hashed: str) -> bool:
|
| 29 |
return pwd_context.verify(plain, hashed)
|
| 30 |
|
| 31 |
-
# Create a JWT access token
|
| 32 |
def create_access_token(data: dict, expires_delta: timedelta = None):
|
| 33 |
to_encode = data.copy()
|
| 34 |
expire = datetime.utcnow() + (expires_delta or timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
|
|
@@ -37,7 +34,6 @@ def create_access_token(data: dict, expires_delta: timedelta = None):
|
|
| 37 |
logger.debug(f"Created JWT for {data.get('sub')}, expires at {expire}")
|
| 38 |
return encoded_jwt
|
| 39 |
|
| 40 |
-
# Get the current user from the JWT token
|
| 41 |
async def get_current_user(request: Request, token: str = Depends(oauth2_scheme)):
|
| 42 |
auth_header = request.headers.get("Authorization", "No Authorization header")
|
| 43 |
logger.debug(f"Raw Authorization header: {auth_header}")
|
|
|
|
| 20 |
# Password hashing context
|
| 21 |
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
| 22 |
|
|
|
|
| 23 |
def hash_password(password: str) -> str:
|
| 24 |
return pwd_context.hash(password)
|
| 25 |
|
|
|
|
| 26 |
def verify_password(plain: str, hashed: str) -> bool:
|
| 27 |
return pwd_context.verify(plain, hashed)
|
| 28 |
|
|
|
|
| 29 |
def create_access_token(data: dict, expires_delta: timedelta = None):
|
| 30 |
to_encode = data.copy()
|
| 31 |
expire = datetime.utcnow() + (expires_delta or timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
|
|
|
|
| 34 |
logger.debug(f"Created JWT for {data.get('sub')}, expires at {expire}")
|
| 35 |
return encoded_jwt
|
| 36 |
|
|
|
|
| 37 |
async def get_current_user(request: Request, token: str = Depends(oauth2_scheme)):
|
| 38 |
auth_header = request.headers.get("Authorization", "No Authorization header")
|
| 39 |
logger.debug(f"Raw Authorization header: {auth_header}")
|