Skip to content

Commit 4506bf7

Browse files
fix: skip lifetime resolution when exp is already provided
1 parent 453c487 commit 4506bf7

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/apps/authentication/services/security.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def token_expiration_minutes(
5050
@staticmethod
5151
def create_access_token(data: dict) -> str:
5252
to_encode = data.copy()
53-
minutes = AuthenticationService.token_expiration_minutes(
54-
to_encode.get(JWTClaim.client),
55-
settings.authentication.access_token.expiration,
56-
settings.authentication.access_token.web_admin_expiration,
57-
)
58-
expire = datetime.now(timezone.utc) + timedelta(minutes=minutes)
59-
to_encode.setdefault(JWTClaim.exp, expire)
53+
if JWTClaim.exp not in to_encode:
54+
minutes = AuthenticationService.token_expiration_minutes(
55+
to_encode.get(JWTClaim.client),
56+
settings.authentication.access_token.expiration,
57+
settings.authentication.access_token.web_admin_expiration,
58+
)
59+
to_encode[JWTClaim.exp] = datetime.now(timezone.utc) + timedelta(minutes=minutes)
6060
to_encode.setdefault(JWTClaim.jti, str(uuid.uuid4()))
6161
encoded_jwt = jwt.encode(
6262
to_encode,
@@ -134,13 +134,13 @@ def decode_mfa_token(token: str) -> str:
134134
@staticmethod
135135
def create_refresh_token(data: dict) -> str:
136136
to_encode = data.copy()
137-
minutes = AuthenticationService.token_expiration_minutes(
138-
to_encode.get(JWTClaim.client),
139-
settings.authentication.refresh_token.expiration,
140-
settings.authentication.refresh_token.web_admin_expiration,
141-
)
142-
expire = datetime.now(timezone.utc) + timedelta(minutes=minutes)
143-
to_encode.setdefault(JWTClaim.exp, expire)
137+
if JWTClaim.exp not in to_encode:
138+
minutes = AuthenticationService.token_expiration_minutes(
139+
to_encode.get(JWTClaim.client),
140+
settings.authentication.refresh_token.expiration,
141+
settings.authentication.refresh_token.web_admin_expiration,
142+
)
143+
to_encode[JWTClaim.exp] = datetime.now(timezone.utc) + timedelta(minutes=minutes)
144144
to_encode.setdefault(JWTClaim.jti, str(uuid.uuid4()))
145145
encoded_jwt = jwt.encode(
146146
to_encode,

0 commit comments

Comments
 (0)