aiteamutils 0.2.21__py3-none-any.whl → 0.2.23__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ from fastapi.security import OAuth2PasswordBearer
4
4
  from jose import JWTError, jwt
5
5
  from sqlalchemy.ext.asyncio import AsyncSession
6
6
 
7
- from .database import DatabaseService, get_database_service
7
+ from .database import DatabaseService, get_database_service, get_db
8
8
  from .exceptions import CustomException, ErrorCode
9
9
  from .config import get_settings
10
10
 
aiteamutils/security.py CHANGED
@@ -268,24 +268,24 @@ async def create_jwt_token(
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
- TokenCreationError: 토큰 생성 실패 시
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)}",
@@ -297,12 +297,28 @@ async def create_jwt_token(
297
297
  if token_type == "access":
298
298
  expires_at = datetime.now(UTC) + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
299
299
  token_data = {
300
+ # 등록 클레임
300
301
  "iss": settings.TOKEN_ISSUER,
301
302
  "sub": user_data["username"],
302
303
  "aud": settings.TOKEN_AUDIENCE,
303
304
  "exp": expires_at,
305
+
306
+ # 공개 클레임
307
+ "username": user_data["username"],
308
+ "name": user_data.get("name"),
309
+
310
+ # 비공개 클레임
311
+ "user_ulid": user_data["ulid"],
312
+ "role_ulid": user_data.get("role_ulid"),
313
+ "status": user_data.get("status"),
314
+ "last_login": datetime.now(UTC).isoformat(),
304
315
  "token_type": token_type,
305
- **user_data
316
+
317
+ # 조직 관련 클레임
318
+ "organization_ulid": user_data.get("organization_ulid"),
319
+ "organization_id": user_data.get("organization_id"),
320
+ "organization_name": user_data.get("organization_name"),
321
+ "company_name": user_data.get("company_name")
306
322
  }
307
323
  else: # refresh token
308
324
  expires_at = datetime.now(UTC) + timedelta(days=14)
aiteamutils/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  """버전 정보"""
2
- __version__ = "0.2.21"
2
+ __version__ = "0.2.23"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiteamutils
3
- Version: 0.2.21
3
+ Version: 0.2.23
4
4
  Summary: AI Team Utilities
5
5
  Project-URL: Homepage, https://github.com/yourusername/aiteamutils
6
6
  Project-URL: Issues, https://github.com/yourusername/aiteamutils/issues
@@ -5,12 +5,12 @@ aiteamutils/base_service.py,sha256=E4dHGE0DvhmRyFplh46SwKJOSF_nUL7OAsCkf_ZJF_8,2
5
5
  aiteamutils/cache.py,sha256=tr0Yn8VPYA9QHiKCUzciVlQ2J1RAwNo2K9lGMH4rY3s,1334
6
6
  aiteamutils/config.py,sha256=7pJHBml8RRXC9FpoRBx0emofFkvtxsyk9_Rcur2F9hI,2724
7
7
  aiteamutils/database.py,sha256=raYKRZjEfefM3SnoPYozPu7OUGm62XWOUqZzN4_cayw,33479
8
- aiteamutils/dependencies.py,sha256=gy1G4DFb-UooFDFZOSIThEDDCUtsJn9odnm5dKV1kQM,4000
8
+ aiteamutils/dependencies.py,sha256=e5P-DQi5OMMh7FADaAUqU0kLVBcReE7za55EDNZN950,4008
9
9
  aiteamutils/enums.py,sha256=ipZi6k_QD5-3QV7Yzv7bnL0MjDz-vqfO9I5L77biMKs,632
10
10
  aiteamutils/exceptions.py,sha256=YV-ISya4wQlHk4twvGo16I5r8h22-tXpn9wa-b3WwDM,15231
11
- aiteamutils/security.py,sha256=2k5j8iV4jkp0IGRmOtEbVyoeuoDHbguzaYju0Wm-mmI,12715
11
+ aiteamutils/security.py,sha256=4J9Q18RvlHH3zD8gW8ymFio7k5JuIJxvS2blU19AipA,13458
12
12
  aiteamutils/validators.py,sha256=3N245cZFjgwtW_KzjESkizx5BBUDaJLbbxfNO4WOFZ0,7764
13
- aiteamutils/version.py,sha256=Cm_lURyI4GuJ_Ec6ukumU-cRzbGIFhPP_6hKl8HcuS8,44
14
- aiteamutils-0.2.21.dist-info/METADATA,sha256=AyaS1T8470tkEw0iyTdXbrCGkz4w4dICfBPOwblO9Cg,1718
15
- aiteamutils-0.2.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- aiteamutils-0.2.21.dist-info/RECORD,,
13
+ aiteamutils/version.py,sha256=FoxokvvxnU_rqoyqNTry6Th-i69tCu9uLXqkhxLbDwU,44
14
+ aiteamutils-0.2.23.dist-info/METADATA,sha256=S-LkVpOYUZgX1BssQ9c144uavb-3FjiKsR4RJNYBIS0,1718
15
+ aiteamutils-0.2.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ aiteamutils-0.2.23.dist-info/RECORD,,