Skip to content

Commit 8521b42

Browse files
committed
feat: время для JWT в .env теперь в секундах, Resolve #14
1 parent ac756ff commit 8521b42

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

.env.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ REDIS_OUT_PORT=6379
2727
REDIS_PORT=6379
2828

2929
# ===== JWT =====
30-
# Time is in minutes
31-
# 43200 minutes = 30 days
32-
AUTH_ACCESS_TOKEN_EXPIRES_IN=15
33-
AUTH_REFRESH_TOKEN_EXPIRES_IN=43200
30+
# Time is in seconds
31+
# 2592000 seconds = 30 days
32+
AUTH_ACCESS_TOKEN_EXPIRES_IN=900
33+
AUTH_REFRESH_TOKEN_EXPIRES_IN=2592000
3434
AUTH_JWT_ALGORITHM=HS256
3535
AUTH_JWT_SECRET=SECRET
3636

.env.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ REDIS_PORT=6379
2525
REDIS_OUT_PORT=6380
2626

2727
# ===== JWT (test) =====
28-
AUTH_ACCESS_TOKEN_EXPIRES_IN=15
29-
AUTH_REFRESH_TOKEN_EXPIRES_IN=60
28+
# Time is in seconds
29+
# 2592000 seconds = 30 days
30+
AUTH_ACCESS_TOKEN_EXPIRES_IN=900
31+
AUTH_REFRESH_TOKEN_EXPIRES_IN=2592000
3032
AUTH_JWT_ALGORITHM=HS256
3133
AUTH_JWT_SECRET=TEST_SECRET
3234

src/auth/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
class AuthSettings(BaseSettings):
10-
access_token_expires_in: int # минуты
11-
refresh_token_expires_in: int # минуты
10+
access_token_expires_in: int # секунды
11+
refresh_token_expires_in: int # секунды
1212

1313
jwt_algorithm: str
1414
jwt_secret: str

src/auth/services/redis_refresh_token_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async def add_new_refresh_token(user_id: UUID, token_jti: UUID) -> None:
2020
pipe = redis_client.pipeline()
2121
pipe.zadd(key, {str(token_jti): int(time.time())})
2222
pipe.zcard(key)
23-
pipe.expire(key, auth_settings.refresh_token_expires_in * 60)
23+
pipe.expire(key, auth_settings.refresh_token_expires_in)
2424

2525
results = await pipe.execute()
2626
count = results[1]

src/auth/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_access_token(cls, user_id: str | UUID) -> str:
5959
payload = {
6060
"iat": now,
6161
"sub": str(user_id),
62-
"exp": now + timedelta(minutes=cls.__auth_settings.access_token_expires_in),
62+
"exp": now + timedelta(seconds=cls.__auth_settings.access_token_expires_in),
6363
}
6464

6565
return jwt.encode(
@@ -80,7 +80,7 @@ def create_refresh_token(cls, user_id: str | UUID) -> RefreshTokenDataSchema:
8080
payload = {
8181
"iat": now,
8282
"sub": str(user_id),
83-
"exp": now + timedelta(minutes=cls.__auth_settings.refresh_token_expires_in),
83+
"exp": now + timedelta(seconds=cls.__auth_settings.refresh_token_expires_in),
8484
"jti": str(jti),
8585
}
8686

0 commit comments

Comments
 (0)