|
14 | 14 | from __future__ import annotations |
15 | 15 |
|
16 | 16 | import json |
17 | | -from datetime import datetime |
18 | 17 | from typing import TYPE_CHECKING, Any, Callable, Dict, Optional |
19 | 18 |
|
20 | 19 | from supertokens_python.framework import BaseRequest |
|
33 | 32 | from . import session_functions |
34 | 33 | from .access_token import validate_access_token_structure |
35 | 34 | from .cookie_and_header import ( |
| 35 | + anti_csrf_response_mutator, |
| 36 | + clear_session_response_mutator, |
| 37 | + front_token_response_mutator, |
36 | 38 | get_anti_csrf_header, |
37 | 39 | get_rid_header, |
38 | 40 | get_token, |
39 | | - token_response_mutator, |
40 | | - front_token_response_mutator, |
41 | | - anti_csrf_response_mutator, |
42 | 41 | set_cookie_response_mutator, |
43 | | - clear_session_response_mutator, |
| 42 | + token_response_mutator, |
44 | 43 | ) |
45 | 44 | from .exceptions import ( |
46 | 45 | TokenTheftError, |
|
50 | 49 | ) |
51 | 50 | from .interfaces import ( |
52 | 51 | AccessTokenObj, |
53 | | - ResponseMutator, |
54 | 52 | ClaimsValidationResult, |
55 | 53 | GetClaimValueOkResult, |
56 | 54 | JSONObject, |
57 | 55 | RecipeInterface, |
58 | 56 | RegenerateAccessTokenOkResult, |
| 57 | + ResponseMutator, |
59 | 58 | SessionClaim, |
60 | 59 | SessionClaimValidator, |
61 | 60 | SessionDoesNotExistError, |
|
64 | 63 | ) |
65 | 64 | from .jwt import ParsedJWTInfo, parse_jwt_without_signature_verification |
66 | 65 | from .session_class import Session |
67 | | -from .utils import SessionConfig, TokenTransferMethod, validate_claims_in_payload |
| 66 | +from .utils import ( |
| 67 | + HUNDRED_YEARS_IN_MS, |
| 68 | + SessionConfig, |
| 69 | + TokenTransferMethod, |
| 70 | + validate_claims_in_payload, |
| 71 | +) |
68 | 72 |
|
69 | 73 | if TYPE_CHECKING: |
70 | 74 | from typing import List, Union |
71 | 75 | from supertokens_python import AppInfo |
72 | 76 | from supertokens_python.querier import Querier |
73 | 77 |
|
74 | | - |
75 | 78 | from .constants import available_token_transfer_methods |
76 | 79 | from .interfaces import SessionContainer |
77 | 80 |
|
@@ -248,12 +251,16 @@ async def create_new_session( |
248 | 251 | new_session.access_token_payload, |
249 | 252 | ) |
250 | 253 | ) |
| 254 | + # We set the expiration to 100 years, because we can't really access the expiration of the refresh token everywhere we are setting it. |
| 255 | + # This should be safe to do, since this is only the validity of the cookie (set here or on the frontend) but we check the expiration of the JWT anyway. |
| 256 | + # Even if the token is expired the presence of the token indicates that the user could have a valid refresh |
| 257 | + # Setting them to infinity would require special case handling on the frontend and just adding 10 years seems enough. |
251 | 258 | response_mutators.append( |
252 | 259 | token_response_mutator( |
253 | 260 | self.config, |
254 | 261 | "access", |
255 | 262 | new_access_token_info["token"], |
256 | | - int(datetime.now().timestamp()) + 3153600000000, |
| 263 | + get_timestamp_ms() + HUNDRED_YEARS_IN_MS, |
257 | 264 | new_session.transfer_method, |
258 | 265 | ) |
259 | 266 | ) |
@@ -456,12 +463,16 @@ async def get_session( |
456 | 463 | session.access_token_payload, |
457 | 464 | ) |
458 | 465 | ) |
| 466 | + # We set the expiration to 100 years, because we can't really access the expiration of the refresh token everywhere we are setting it. |
| 467 | + # This should be safe to do, since this is only the validity of the cookie (set here or on the frontend) but we check the expiration of the JWT anyway. |
| 468 | + # Even if the token is expired the presence of the token indicates that the user could have a valid refresh |
| 469 | + # Setting them to infinity would require special case handling on the frontend and just adding 10 years seems enough. |
459 | 470 | session.response_mutators.append( |
460 | 471 | token_response_mutator( |
461 | 472 | self.config, |
462 | 473 | "access", |
463 | 474 | session.access_token, |
464 | | - int(datetime.now().timestamp()) + 3153600000000, |
| 475 | + get_timestamp_ms() + HUNDRED_YEARS_IN_MS, |
465 | 476 | session.transfer_method, |
466 | 477 | ) |
467 | 478 | ) |
@@ -603,12 +614,16 @@ async def refresh_session( |
603 | 614 | session.access_token_payload, |
604 | 615 | ) |
605 | 616 | ) |
| 617 | + # We set the expiration to 100 years, because we can't really access the expiration of the refresh token everywhere we are setting it. |
| 618 | + # This should be safe to do, since this is only the validity of the cookie (set here or on the frontend) but we check the expiration of the JWT anyway. |
| 619 | + # Even if the token is expired the presence of the token indicates that the user could have a valid refresh |
| 620 | + # Setting them to infinity would require special case handling on the frontend and just adding 10 years seems enough. |
606 | 621 | response_mutators.append( |
607 | 622 | token_response_mutator( |
608 | 623 | self.config, |
609 | 624 | "access", |
610 | 625 | new_access_token_info["token"], |
611 | | - int(datetime.now().timestamp()) + 3153600000000, |
| 626 | + get_timestamp_ms() + HUNDRED_YEARS_IN_MS, # 100 years |
612 | 627 | session.transfer_method, |
613 | 628 | ) |
614 | 629 | ) |
|
0 commit comments