Skip to content

Commit 46272a0

Browse files
Refactor JWT handling to define SECRET_KEY and update token generation logic
1 parent 2ada3b2 commit 46272a0

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed
0 Bytes
Binary file not shown.
190 Bytes
Binary file not shown.

Backend/FastAPI/routers/jwt_oauth_users.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232

3333
ALGORITHM = "HS256" # Algoritmo de firma del token (HMAC con SHA-256).
3434

35-
# SECRET_KEY = "d8f3e5c6b7a9c0d1e2f3a4b5c6d7e8f9g0h1i2j3k4l5m6n7o8p9q0r1s2t3u4v5"
36-
# # Clave secreta usada para firmar y verificar el token (debe ser segura y secreta).
35+
# -------------------- CLAVE SECRETA PARA FIRMAR EL TOKEN --------------------
36+
37+
SECRET_KEY = "d8f3e5c6b7a9c0d1e2f3a4b5c6d7e8f9g0h1i2j3k4l5m6n7o8p9q0r1s2t3u4v5"
38+
# Clave secreta usada para firmar y verificar el token (debe ser segura y secreta).
3739

3840
# -------------------- DURACION DEL TOKEN --------------------
3941

@@ -138,14 +140,14 @@ async def login(form : OAuth2PasswordRequestForm = Depends() ):
138140
# UTC -> Tiempo Universal Coordinado (zona horaria estándar)
139141
expire = datetime.now(UTC) + access_token_expiration # Tiempo de expiración del token
140142

141-
access_token = {
143+
payload = {
142144
"sub" : user.username,
143145
"exp" : expire
144146
} # Payload del token (datos que contiene)
145147

146148
# Si pasa las validaciones -> se devuelve un "access token".
147149
return {
148-
"Access_Token" : access_token, # Aquí el "token" es simplemente el username.
150+
"Access_Token" : jwt.encode(payload, SECRET_KEY, algorithm = ALGORITHM), # Genera el token JWT
149151
"Token_type" : "bearer" # Tipo de token usado en OAuth2
150152
}
151153

0 commit comments

Comments
 (0)