aiteamutils 0.2.22__tar.gz → 0.2.24__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/PKG-INFO +1 -1
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/security.py +24 -9
- aiteamutils-0.2.24/aiteamutils/version.py +2 -0
- aiteamutils-0.2.22/aiteamutils/version.py +0 -2
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/.gitignore +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/README.md +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/__init__.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/database.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/dependencies.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/pyproject.toml +0 -0
- {aiteamutils-0.2.22 → aiteamutils-0.2.24}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
"""보안 관련 유틸리티."""
|
2
2
|
from datetime import datetime, timedelta, UTC
|
3
|
-
from typing import Dict, Any, Optional, Literal, Callable
|
3
|
+
from typing import Dict, Any, Optional, Literal, Callable, Type, Base
|
4
4
|
from fastapi import Request, HTTPException, status
|
5
5
|
from functools import wraps
|
6
6
|
from jose import jwt, JWTError
|
@@ -262,30 +262,30 @@ async def create_jwt_token(
|
|
262
262
|
user_data: Dict[str, Any],
|
263
263
|
token_type: Literal["access", "refresh"],
|
264
264
|
db_service: DatabaseService,
|
265
|
-
log_model:
|
265
|
+
log_model: Type[Base],
|
266
266
|
request: Optional[Request] = None
|
267
267
|
) -> str:
|
268
268
|
"""JWT 토큰을 생성하고 로그를 기록합니다.
|
269
269
|
|
270
270
|
Args:
|
271
|
-
user_data: 사용자 데이터 (username, ulid 등
|
271
|
+
user_data: 사용자 데이터 딕셔너리 (username, ulid, name, role_ulid, status, organization 정보 등)
|
272
272
|
token_type: 토큰 타입 ("access" 또는 "refresh")
|
273
273
|
db_service: 데이터베이스 서비스
|
274
|
-
log_model:
|
274
|
+
log_model: 로그 모델 클래스
|
275
275
|
request: FastAPI 요청 객체
|
276
276
|
|
277
277
|
Returns:
|
278
278
|
str: 생성된 JWT 토큰
|
279
279
|
|
280
280
|
Raises:
|
281
|
-
|
282
|
-
SecurityError: 기타 보안 관련 오류 발생 시
|
281
|
+
CustomException: 토큰 생성 실패 시
|
283
282
|
"""
|
284
283
|
try:
|
285
284
|
settings = get_settings()
|
285
|
+
|
286
286
|
# 필수 필드 검증
|
287
287
|
required_fields = {"username", "ulid"}
|
288
|
-
missing_fields = required_fields - user_data.keys()
|
288
|
+
missing_fields = required_fields - set(user_data.keys())
|
289
289
|
if missing_fields:
|
290
290
|
raise TokenCreationError(
|
291
291
|
detail=f"Missing required fields: {', '.join(missing_fields)}",
|
@@ -293,16 +293,31 @@ async def create_jwt_token(
|
|
293
293
|
token_type=token_type
|
294
294
|
)
|
295
295
|
|
296
|
-
# 토큰 데이터 생성
|
297
296
|
if token_type == "access":
|
298
297
|
expires_at = datetime.now(UTC) + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
299
298
|
token_data = {
|
299
|
+
# 등록 클레임
|
300
300
|
"iss": settings.TOKEN_ISSUER,
|
301
301
|
"sub": user_data["username"],
|
302
302
|
"aud": settings.TOKEN_AUDIENCE,
|
303
303
|
"exp": expires_at,
|
304
|
+
|
305
|
+
# 공개 클레임
|
306
|
+
"username": user_data["username"],
|
307
|
+
"name": user_data.get("name"),
|
308
|
+
|
309
|
+
# 비공개 클레임
|
310
|
+
"user_ulid": user_data["ulid"],
|
311
|
+
"role_ulid": user_data.get("role_ulid"),
|
312
|
+
"status": user_data.get("status"),
|
313
|
+
"last_login": datetime.now(UTC).isoformat(),
|
304
314
|
"token_type": token_type,
|
305
|
-
|
315
|
+
|
316
|
+
# 조직 관련 클레임
|
317
|
+
"organization_ulid": user_data.get("organization_ulid"),
|
318
|
+
"organization_id": user_data.get("organization_id"),
|
319
|
+
"organization_name": user_data.get("organization_name"),
|
320
|
+
"company_name": user_data.get("company_name")
|
306
321
|
}
|
307
322
|
else: # refresh token
|
308
323
|
expires_at = datetime.now(UTC) + timedelta(days=14)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|