@spfn/auth 0.2.0-beta.62 → 0.2.0-beta.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as AuthInitOptions, d as VerificationPurpose, h as PermissionCategory, j as AuthContext } from './authenticate-DcOkuB7d.js';
2
- export { u as ChangePasswordParams, p as CheckAccountExistsParams, C as CheckAccountExistsResult, a1 as EmailSchema, I as IssueOneTimeTokenResult, s as LoginParams, L as LoginResult, t as LogoutParams, Z as OAuthCallbackParams, _ as OAuthCallbackResult, Y as OAuthStartParams, O as OAuthStartResult, a3 as PasswordSchema, a2 as PhoneSchema, q as RegisterParams, F as RegisterPublicKeyParams, a as RegisterResult, H as RevokeKeyParams, G as RotateKeyParams, b as RotateKeyResult, x as SendVerificationCodeParams, S as SendVerificationCodeResult, a4 as TargetTypeSchema, f as VERIFICATION_PURPOSES, e as VERIFICATION_TARGET_TYPES, a5 as VerificationPurposeSchema, V as VerificationTargetType, y as VerifyCodeParams, z as VerifyCodeResult, m as authRouter, $ as authenticate, Q as buildOAuthErrorUrl, o as changePasswordService, k as checkAccountExistsService, W as getEnabledOAuthProviders, X as getGoogleAccessToken, T as isOAuthProviderEnabled, J as issueOneTimeTokenService, l as loginService, n as logoutService, N as oauthCallbackService, M as oauthStartService, a0 as optionalAuth, B as registerPublicKeyService, r as registerService, E as revokeKeyService, D as rotateKeyService, v as sendVerificationCodeService, w as verifyCodeService, K as verifyOneTimeTokenService } from './authenticate-DcOkuB7d.js';
1
+ import { i as AuthInitOptions, j as OAuthProvider, d as VerificationPurpose, h as PermissionCategory, k as AuthContext } from './authenticate-mfVRzeIK.js';
2
+ export { v as ChangePasswordParams, q as CheckAccountExistsParams, C as CheckAccountExistsResult, a3 as EmailSchema, I as IssueOneTimeTokenResult, t as LoginParams, L as LoginResult, u as LogoutParams, a8 as NormalizedIdentity, $ as OAuthCallbackParams, a0 as OAuthCallbackResult, _ as OAuthStartParams, O as OAuthStartResult, a9 as OAuthTokens, a5 as PasswordSchema, a4 as PhoneSchema, s as RegisterParams, G as RegisterPublicKeyParams, a as RegisterResult, J as RevokeKeyParams, H as RotateKeyParams, b as RotateKeyResult, y as SendVerificationCodeParams, S as SendVerificationCodeResult, a6 as TargetTypeSchema, f as VERIFICATION_PURPOSES, e as VERIFICATION_TARGET_TYPES, a7 as VerificationPurposeSchema, V as VerificationTargetType, z as VerifyCodeParams, B as VerifyCodeResult, m as authRouter, a1 as authenticate, T as buildOAuthErrorUrl, p as changePasswordService, l as checkAccountExistsService, Y as getEnabledOAuthProviders, Z as getGoogleAccessToken, ab as getOAuthProvider, ac as getRegisteredProviders, W as isOAuthProviderEnabled, K as issueOneTimeTokenService, n as loginService, o as logoutService, Q as oauthCallbackService, N as oauthStartService, a2 as optionalAuth, aa as registerOAuthProvider, D as registerPublicKeyService, r as registerService, X as requireEnabledProvider, F as revokeKeyService, E as rotateKeyService, w as sendVerificationCodeService, x as verifyCodeService, M as verifyOneTimeTokenService } from './authenticate-mfVRzeIK.js';
3
3
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
4
4
  import { K as KeyAlgorithmType, b as InvitationStatus, d as SocialProvider } from './types-B4auHIax.js';
5
5
  export { I as INVITATION_STATUSES, a as KEY_ALGORITHM, S as SOCIAL_PROVIDERS, U as USER_STATUSES, c as UserStatus } from './types-B4auHIax.js';
@@ -1333,7 +1333,7 @@ declare function getAuthSessionService(userId: string | number | bigint): Promis
1333
1333
  id: number;
1334
1334
  name: string;
1335
1335
  displayName: string;
1336
- category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
1336
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
1337
1337
  }[];
1338
1338
  userId: number;
1339
1339
  publicId: string;
@@ -1416,6 +1416,127 @@ declare function updateLocaleService(userId: string | number | bigint, locale: s
1416
1416
  */
1417
1417
  declare function updateUserProfileService(userId: string | number | bigint, params: UpdateProfileParams): Promise<ProfileInfo>;
1418
1418
 
1419
+ /**
1420
+ * Google OAuth 2.0 Client
1421
+ *
1422
+ * Authorization Code Flow 구현
1423
+ * - getGoogleAuthUrl: Google 로그인 URL 생성
1424
+ * - exchangeCodeForTokens: Code를 Token으로 교환
1425
+ * - getGoogleUserInfo: 사용자 정보 조회
1426
+ */
1427
+ interface GoogleTokenResponse {
1428
+ access_token: string;
1429
+ expires_in: number;
1430
+ refresh_token?: string;
1431
+ scope: string;
1432
+ token_type: string;
1433
+ id_token?: string;
1434
+ }
1435
+ interface GoogleUserInfo {
1436
+ id: string;
1437
+ email: string;
1438
+ verified_email: boolean;
1439
+ name?: string;
1440
+ given_name?: string;
1441
+ family_name?: string;
1442
+ picture?: string;
1443
+ locale?: string;
1444
+ }
1445
+ /**
1446
+ * Google OAuth가 활성화되어 있는지 확인
1447
+ */
1448
+ declare function isGoogleOAuthEnabled(): boolean;
1449
+ /**
1450
+ * Google OAuth 설정 가져오기
1451
+ */
1452
+ declare function getGoogleOAuthConfig(): {
1453
+ clientId: string;
1454
+ clientSecret: string;
1455
+ redirectUri: string;
1456
+ };
1457
+ /**
1458
+ * Google 로그인 URL 생성
1459
+ *
1460
+ * @param state - CSRF 방지용 state 파라미터 (암호화된 returnUrl + nonce 포함)
1461
+ * @param scopes - 요청할 OAuth scopes (기본: env 또는 email, profile)
1462
+ */
1463
+ declare function getGoogleAuthUrl(state: string, scopes?: string[]): string;
1464
+ /**
1465
+ * Authorization Code를 Token으로 교환
1466
+ *
1467
+ * @param code - Google에서 받은 authorization code
1468
+ */
1469
+ declare function exchangeCodeForTokens(code: string): Promise<GoogleTokenResponse>;
1470
+ /**
1471
+ * Access Token으로 Google 사용자 정보 조회
1472
+ *
1473
+ * @param accessToken - Google access token
1474
+ */
1475
+ declare function getGoogleUserInfo(accessToken: string): Promise<GoogleUserInfo>;
1476
+ /**
1477
+ * Refresh Token으로 새 Access Token 획득
1478
+ *
1479
+ * @param refreshToken - Google refresh token
1480
+ */
1481
+ declare function refreshAccessToken(refreshToken: string): Promise<GoogleTokenResponse>;
1482
+
1483
+ /**
1484
+ * OAuth State Management
1485
+ *
1486
+ * CSRF 방지를 위한 state 파라미터 암호화/복호화
1487
+ * - returnUrl: OAuth 성공 후 리다이렉트할 URL
1488
+ * - nonce: CSRF 방지용 일회용 토큰
1489
+ * - provider: OAuth provider (google, github 등)
1490
+ * - publicKey, keyId, fingerprint, algorithm: 클라이언트 키 정보
1491
+ * - expiresAt: state 만료 시간
1492
+ */
1493
+
1494
+ interface OAuthState {
1495
+ returnUrl: string;
1496
+ nonce: string;
1497
+ provider: string;
1498
+ publicKey: string;
1499
+ keyId: string;
1500
+ fingerprint: string;
1501
+ algorithm: KeyAlgorithmType;
1502
+ metadata?: Record<string, unknown>;
1503
+ }
1504
+ interface CreateOAuthStateParams {
1505
+ provider: string;
1506
+ returnUrl: string;
1507
+ publicKey: string;
1508
+ keyId: string;
1509
+ fingerprint: string;
1510
+ algorithm: KeyAlgorithmType;
1511
+ metadata?: Record<string, unknown>;
1512
+ }
1513
+ /**
1514
+ * OAuth state 생성 및 암호화
1515
+ *
1516
+ * @param params - state 생성에 필요한 파라미터
1517
+ * @returns 암호화된 state 문자열
1518
+ */
1519
+ declare function createOAuthState(params: CreateOAuthStateParams): Promise<string>;
1520
+ /**
1521
+ * OAuth state 복호화 및 검증
1522
+ *
1523
+ * @param encryptedState - 암호화된 state 문자열
1524
+ * @returns 복호화된 state 객체
1525
+ * @throws Error if state is invalid or expired (JWE exp claim으로 자동 검증)
1526
+ */
1527
+ declare function verifyOAuthState(encryptedState: string): Promise<OAuthState>;
1528
+
1529
+ /**
1530
+ * Google OAuthProvider 구현
1531
+ *
1532
+ * 기존 google.ts의 함수를 OAuthProvider 인터페이스로 래핑한다.
1533
+ * google.ts 자체는 그대로 유지(테스트·google 전용 route가 직접 의존).
1534
+ *
1535
+ * 이 모듈을 import 하는 것만으로 google provider가 registry에 자기 등록된다.
1536
+ */
1537
+
1538
+ declare const googleProvider: OAuthProvider;
1539
+
1419
1540
  /**
1420
1541
  * @spfn/auth - Database Schema Definition
1421
1542
  *
@@ -2474,7 +2595,7 @@ declare const permissions: drizzle_orm_pg_core.PgTableWithColumns<{
2474
2595
  tableName: "permissions";
2475
2596
  dataType: "string";
2476
2597
  columnType: "PgText";
2477
- data: "auth" | "custom" | "user" | "rbac" | "system";
2598
+ data: "custom" | "user" | "auth" | "rbac" | "system";
2478
2599
  driverParam: string;
2479
2600
  notNull: false;
2480
2601
  hasDefault: false;
@@ -3065,17 +3186,17 @@ declare class UsersRepository extends BaseRepository {
3065
3186
  * Write primary 사용
3066
3187
  */
3067
3188
  create(data: NewUser): Promise<{
3189
+ username: string | null;
3190
+ status: "active" | "inactive" | "suspended";
3068
3191
  email: string | null;
3069
3192
  phone: string | null;
3070
3193
  id: number;
3194
+ createdAt: Date;
3195
+ updatedAt: Date;
3071
3196
  publicId: string;
3072
- username: string | null;
3073
3197
  passwordHash: string | null;
3074
3198
  passwordChangeRequired: boolean;
3075
3199
  roleId: number;
3076
- createdAt: Date;
3077
- updatedAt: Date;
3078
- status: "active" | "inactive" | "suspended";
3079
3200
  emailVerifiedAt: Date | null;
3080
3201
  phoneVerifiedAt: Date | null;
3081
3202
  lastLoginAt: Date | null;
@@ -3145,17 +3266,17 @@ declare class UsersRepository extends BaseRepository {
3145
3266
  * Write primary 사용
3146
3267
  */
3147
3268
  deleteById(id: number): Promise<{
3269
+ username: string | null;
3270
+ status: "active" | "inactive" | "suspended";
3148
3271
  email: string | null;
3149
3272
  phone: string | null;
3150
3273
  id: number;
3274
+ createdAt: Date;
3275
+ updatedAt: Date;
3151
3276
  publicId: string;
3152
- username: string | null;
3153
3277
  passwordHash: string | null;
3154
3278
  passwordChangeRequired: boolean;
3155
3279
  roleId: number;
3156
- createdAt: Date;
3157
- updatedAt: Date;
3158
- status: "active" | "inactive" | "suspended";
3159
3280
  emailVerifiedAt: Date | null;
3160
3281
  phoneVerifiedAt: Date | null;
3161
3282
  lastLoginAt: Date | null;
@@ -3178,7 +3299,7 @@ declare class UsersRepository extends BaseRepository {
3178
3299
  id: number;
3179
3300
  name: string;
3180
3301
  displayName: string;
3181
- category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
3302
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
3182
3303
  }[];
3183
3304
  }>;
3184
3305
  /**
@@ -3293,16 +3414,16 @@ declare class KeysRepository extends BaseRepository {
3293
3414
  * Write primary 사용
3294
3415
  */
3295
3416
  create(data: NewUserPublicKey): Promise<{
3296
- publicKey: string;
3297
- keyId: string;
3298
- fingerprint: string;
3299
- algorithm: "ES256" | "RS256";
3300
3417
  userId: number;
3418
+ keyId: string;
3301
3419
  id: number;
3302
3420
  isActive: boolean;
3303
3421
  createdAt: Date;
3304
- expiresAt: Date | null;
3422
+ publicKey: string;
3423
+ algorithm: "ES256" | "RS256";
3424
+ fingerprint: string;
3305
3425
  lastUsedAt: Date | null;
3426
+ expiresAt: Date | null;
3306
3427
  revokedAt: Date | null;
3307
3428
  revokedReason: string | null;
3308
3429
  }>;
@@ -3329,16 +3450,16 @@ declare class KeysRepository extends BaseRepository {
3329
3450
  * Write primary 사용
3330
3451
  */
3331
3452
  deleteByKeyIdAndUserId(keyId: string, userId: number): Promise<{
3332
- publicKey: string;
3333
- keyId: string;
3334
- fingerprint: string;
3335
- algorithm: "ES256" | "RS256";
3336
3453
  userId: number;
3454
+ keyId: string;
3337
3455
  id: number;
3338
3456
  isActive: boolean;
3339
3457
  createdAt: Date;
3340
- expiresAt: Date | null;
3458
+ publicKey: string;
3459
+ algorithm: "ES256" | "RS256";
3460
+ fingerprint: string;
3341
3461
  lastUsedAt: Date | null;
3462
+ expiresAt: Date | null;
3342
3463
  revokedAt: Date | null;
3343
3464
  revokedReason: string | null;
3344
3465
  }>;
@@ -3453,14 +3574,14 @@ declare class VerificationCodesRepository extends BaseRepository {
3453
3574
  * Write primary 사용
3454
3575
  */
3455
3576
  create(data: NewVerificationCode): Promise<{
3456
- target: string;
3457
- targetType: "email" | "phone";
3458
- purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3459
- code: string;
3460
3577
  id: number;
3461
3578
  createdAt: Date;
3462
3579
  updatedAt: Date;
3463
3580
  expiresAt: Date;
3581
+ target: string;
3582
+ targetType: "email" | "phone";
3583
+ code: string;
3584
+ purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3464
3585
  usedAt: Date | null;
3465
3586
  attempts: number;
3466
3587
  }>;
@@ -3649,7 +3770,7 @@ declare class PermissionsRepository extends BaseRepository {
3649
3770
  name: string;
3650
3771
  displayName: string;
3651
3772
  description: string | null;
3652
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3773
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3653
3774
  isBuiltin: boolean;
3654
3775
  isSystem: boolean;
3655
3776
  isActive: boolean;
@@ -3665,7 +3786,7 @@ declare class PermissionsRepository extends BaseRepository {
3665
3786
  name: string;
3666
3787
  displayName: string;
3667
3788
  description: string | null;
3668
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3789
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3669
3790
  isBuiltin: boolean;
3670
3791
  isSystem: boolean;
3671
3792
  isActive: boolean;
@@ -3705,7 +3826,7 @@ declare class PermissionsRepository extends BaseRepository {
3705
3826
  name: string;
3706
3827
  displayName: string;
3707
3828
  description: string | null;
3708
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3829
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3709
3830
  isBuiltin: boolean;
3710
3831
  isSystem: boolean;
3711
3832
  isActive: boolean;
@@ -3716,7 +3837,6 @@ declare class PermissionsRepository extends BaseRepository {
3716
3837
  */
3717
3838
  deleteById(id: number): Promise<{
3718
3839
  description: string | null;
3719
- metadata: Record<string, any> | null;
3720
3840
  id: number;
3721
3841
  name: string;
3722
3842
  displayName: string;
@@ -3725,7 +3845,8 @@ declare class PermissionsRepository extends BaseRepository {
3725
3845
  isActive: boolean;
3726
3846
  createdAt: Date;
3727
3847
  updatedAt: Date;
3728
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3848
+ metadata: Record<string, any> | null;
3849
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3729
3850
  }>;
3730
3851
  }
3731
3852
  declare const permissionsRepository: PermissionsRepository;
@@ -3770,9 +3891,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3770
3891
  */
3771
3892
  createMany(data: NewRolePermission[]): Promise<{
3772
3893
  id: number;
3773
- roleId: number;
3774
3894
  createdAt: Date;
3775
3895
  updatedAt: Date;
3896
+ roleId: number;
3776
3897
  permissionId: number;
3777
3898
  }[]>;
3778
3899
  /**
@@ -3788,9 +3909,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3788
3909
  */
3789
3910
  setPermissionsForRole(roleId: number, permissionIds: number[]): Promise<{
3790
3911
  id: number;
3791
- roleId: number;
3792
3912
  createdAt: Date;
3793
3913
  updatedAt: Date;
3914
+ roleId: number;
3794
3915
  permissionId: number;
3795
3916
  }[]>;
3796
3917
  }
@@ -3855,10 +3976,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3855
3976
  id: number;
3856
3977
  createdAt: Date;
3857
3978
  updatedAt: Date;
3858
- permissionId: number;
3859
3979
  expiresAt: Date | null;
3860
- reason: string | null;
3980
+ permissionId: number;
3861
3981
  granted: boolean;
3982
+ reason: string | null;
3862
3983
  }>;
3863
3984
  /**
3864
3985
  * 사용자 권한 오버라이드 업데이트
@@ -3881,10 +4002,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3881
4002
  id: number;
3882
4003
  createdAt: Date;
3883
4004
  updatedAt: Date;
3884
- permissionId: number;
3885
4005
  expiresAt: Date | null;
3886
- reason: string | null;
4006
+ permissionId: number;
3887
4007
  granted: boolean;
4008
+ reason: string | null;
3888
4009
  }>;
3889
4010
  /**
3890
4011
  * 사용자의 모든 권한 오버라이드 삭제
@@ -3962,7 +4083,6 @@ declare class UserProfilesRepository extends BaseRepository {
3962
4083
  * 프로필 생성
3963
4084
  */
3964
4085
  create(data: NewUserProfile): Promise<{
3965
- metadata: Record<string, any> | null;
3966
4086
  userId: number;
3967
4087
  id: number;
3968
4088
  displayName: string | null;
@@ -3980,6 +4100,7 @@ declare class UserProfilesRepository extends BaseRepository {
3980
4100
  location: string | null;
3981
4101
  company: string | null;
3982
4102
  jobTitle: string | null;
4103
+ metadata: Record<string, any> | null;
3983
4104
  }>;
3984
4105
  /**
3985
4106
  * 프로필 업데이트 (by ID)
@@ -4031,7 +4152,6 @@ declare class UserProfilesRepository extends BaseRepository {
4031
4152
  * 프로필 삭제 (by ID)
4032
4153
  */
4033
4154
  deleteById(id: number): Promise<{
4034
- metadata: Record<string, any> | null;
4035
4155
  userId: number;
4036
4156
  id: number;
4037
4157
  displayName: string | null;
@@ -4049,12 +4169,12 @@ declare class UserProfilesRepository extends BaseRepository {
4049
4169
  location: string | null;
4050
4170
  company: string | null;
4051
4171
  jobTitle: string | null;
4172
+ metadata: Record<string, any> | null;
4052
4173
  }>;
4053
4174
  /**
4054
4175
  * 프로필 삭제 (by User ID)
4055
4176
  */
4056
4177
  deleteByUserId(userId: number): Promise<{
4057
- metadata: Record<string, any> | null;
4058
4178
  userId: number;
4059
4179
  id: number;
4060
4180
  displayName: string | null;
@@ -4072,6 +4192,7 @@ declare class UserProfilesRepository extends BaseRepository {
4072
4192
  location: string | null;
4073
4193
  company: string | null;
4074
4194
  jobTitle: string | null;
4195
+ metadata: Record<string, any> | null;
4075
4196
  }>;
4076
4197
  /**
4077
4198
  * 프로필 Upsert (by User ID)
@@ -4080,7 +4201,6 @@ declare class UserProfilesRepository extends BaseRepository {
4080
4201
  * 새로 생성 시 displayName은 필수 (없으면 'User'로 설정)
4081
4202
  */
4082
4203
  upsertByUserId(userId: number, data: Partial<Omit<NewUserProfile, 'userId'>>): Promise<{
4083
- metadata: Record<string, any> | null;
4084
4204
  userId: number;
4085
4205
  id: number;
4086
4206
  displayName: string | null;
@@ -4098,6 +4218,7 @@ declare class UserProfilesRepository extends BaseRepository {
4098
4218
  location: string | null;
4099
4219
  company: string | null;
4100
4220
  jobTitle: string | null;
4221
+ metadata: Record<string, any> | null;
4101
4222
  }>;
4102
4223
  /**
4103
4224
  * User ID로 프로필 데이터 조회 (formatted)
@@ -4224,16 +4345,16 @@ declare class InvitationsRepository extends BaseRepository {
4224
4345
  * 초대 생성
4225
4346
  */
4226
4347
  create(data: NewInvitation): Promise<{
4348
+ status: "pending" | "accepted" | "expired" | "cancelled";
4227
4349
  email: string;
4228
- metadata: Record<string, any> | null;
4229
4350
  id: number;
4230
- roleId: number;
4231
4351
  createdAt: Date;
4232
4352
  updatedAt: Date;
4233
- status: "pending" | "accepted" | "expired" | "cancelled";
4353
+ roleId: number;
4354
+ metadata: Record<string, any> | null;
4355
+ expiresAt: Date;
4234
4356
  token: string;
4235
4357
  invitedBy: number;
4236
- expiresAt: Date;
4237
4358
  acceptedAt: Date | null;
4238
4359
  cancelledAt: Date | null;
4239
4360
  }>;
@@ -4258,16 +4379,16 @@ declare class InvitationsRepository extends BaseRepository {
4258
4379
  * 초대 삭제
4259
4380
  */
4260
4381
  deleteById(id: number): Promise<{
4382
+ status: "pending" | "accepted" | "expired" | "cancelled";
4261
4383
  email: string;
4262
- metadata: Record<string, any> | null;
4263
4384
  id: number;
4264
- roleId: number;
4265
4385
  createdAt: Date;
4266
4386
  updatedAt: Date;
4267
- status: "pending" | "accepted" | "expired" | "cancelled";
4387
+ roleId: number;
4388
+ metadata: Record<string, any> | null;
4389
+ expiresAt: Date;
4268
4390
  token: string;
4269
4391
  invitedBy: number;
4270
- expiresAt: Date;
4271
4392
  acceptedAt: Date | null;
4272
4393
  cancelledAt: Date | null;
4273
4394
  }>;
@@ -4403,59 +4524,69 @@ declare const invitationsRepository: InvitationsRepository;
4403
4524
  * Social Accounts Repository 클래스
4404
4525
  */
4405
4526
  declare class SocialAccountsRepository extends BaseRepository {
4527
+ /**
4528
+ * 저장 row 의 토큰을 평문으로 복호화해 반환한다.
4529
+ *
4530
+ * 레거시 평문(마커 없음)이 감지되면 즉시 재암호화해 저장하는
4531
+ * self-healing 마이그레이션을 수행한다. 호출자에게는 항상 평문이 반환되어
4532
+ * 외부 API 계약(평문 토큰)이 유지된다.
4533
+ */
4534
+ private decryptAccount;
4406
4535
  /**
4407
4536
  * provider와 providerUserId로 소셜 계정 조회
4408
4537
  * Read replica 사용
4409
4538
  */
4410
4539
  findByProviderAndProviderId(provider: SocialProvider, providerUserId: string): Promise<{
4540
+ accessToken: string | null;
4541
+ refreshToken: string | null;
4542
+ userId: number;
4543
+ id: number;
4411
4544
  createdAt: Date;
4412
4545
  updatedAt: Date;
4413
- id: number;
4414
- userId: number;
4415
4546
  provider: "google" | "github" | "kakao" | "naver" | "superself";
4416
4547
  providerUserId: string;
4417
4548
  providerEmail: string | null;
4418
- accessToken: string | null;
4419
- refreshToken: string | null;
4420
4549
  tokenExpiresAt: Date | null;
4421
- }>;
4550
+ } | null>;
4422
4551
  /**
4423
4552
  * userId로 모든 소셜 계정 조회
4424
4553
  * Read replica 사용
4425
4554
  */
4426
- findByUserId(userId: number): Promise<{
4555
+ findByUserId(userId: number): Promise<({
4556
+ accessToken: string | null;
4557
+ refreshToken: string | null;
4558
+ userId: number;
4559
+ id: number;
4427
4560
  createdAt: Date;
4428
4561
  updatedAt: Date;
4429
- id: number;
4430
- userId: number;
4431
4562
  provider: "google" | "github" | "kakao" | "naver" | "superself";
4432
4563
  providerUserId: string;
4433
4564
  providerEmail: string | null;
4434
- accessToken: string | null;
4435
- refreshToken: string | null;
4436
4565
  tokenExpiresAt: Date | null;
4437
- }[]>;
4566
+ } | null)[]>;
4438
4567
  /**
4439
4568
  * userId와 provider로 소셜 계정 조회
4440
4569
  * Read replica 사용
4441
4570
  */
4442
4571
  findByUserIdAndProvider(userId: number, provider: SocialProvider): Promise<{
4572
+ accessToken: string | null;
4573
+ refreshToken: string | null;
4574
+ userId: number;
4575
+ id: number;
4443
4576
  createdAt: Date;
4444
4577
  updatedAt: Date;
4445
- id: number;
4446
- userId: number;
4447
4578
  provider: "google" | "github" | "kakao" | "naver" | "superself";
4448
4579
  providerUserId: string;
4449
4580
  providerEmail: string | null;
4450
- accessToken: string | null;
4451
- refreshToken: string | null;
4452
4581
  tokenExpiresAt: Date | null;
4453
- }>;
4582
+ } | null>;
4454
4583
  /**
4455
4584
  * 소셜 계정 생성
4456
4585
  * Write primary 사용
4457
4586
  */
4458
4587
  create(data: NewUserSocialAccount): Promise<{
4588
+ accessToken: string | null;
4589
+ refreshToken: string | null;
4459
4590
  userId: number;
4460
4591
  id: number;
4461
4592
  createdAt: Date;
@@ -4463,10 +4594,8 @@ declare class SocialAccountsRepository extends BaseRepository {
4463
4594
  provider: "google" | "github" | "kakao" | "naver" | "superself";
4464
4595
  providerUserId: string;
4465
4596
  providerEmail: string | null;
4466
- accessToken: string | null;
4467
- refreshToken: string | null;
4468
4597
  tokenExpiresAt: Date | null;
4469
- }>;
4598
+ } | null>;
4470
4599
  /**
4471
4600
  * 토큰 정보 업데이트
4472
4601
  * Write primary 사용
@@ -4476,17 +4605,17 @@ declare class SocialAccountsRepository extends BaseRepository {
4476
4605
  refreshToken?: string | null;
4477
4606
  tokenExpiresAt?: Date | null;
4478
4607
  }): Promise<{
4608
+ accessToken: string | null;
4609
+ refreshToken: string | null;
4610
+ userId: number;
4611
+ id: number;
4479
4612
  createdAt: Date;
4480
4613
  updatedAt: Date;
4481
- id: number;
4482
- userId: number;
4483
4614
  provider: "google" | "github" | "kakao" | "naver" | "superself";
4484
4615
  providerUserId: string;
4485
4616
  providerEmail: string | null;
4486
- accessToken: string | null;
4487
- refreshToken: string | null;
4488
4617
  tokenExpiresAt: Date | null;
4489
- }>;
4618
+ } | null>;
4490
4619
  /**
4491
4620
  * 소셜 계정 삭제
4492
4621
  * Write primary 사용
@@ -4974,17 +5103,17 @@ declare function getOptionalAuth(c: Context | {
4974
5103
  declare function getUser(c: Context | {
4975
5104
  raw: Context;
4976
5105
  }): {
5106
+ username: string | null;
5107
+ status: "active" | "inactive" | "suspended";
4977
5108
  email: string | null;
4978
5109
  phone: string | null;
4979
5110
  id: number;
5111
+ createdAt: Date;
5112
+ updatedAt: Date;
4980
5113
  publicId: string;
4981
- username: string | null;
4982
5114
  passwordHash: string | null;
4983
5115
  passwordChangeRequired: boolean;
4984
5116
  roleId: number;
4985
- createdAt: Date;
4986
- updatedAt: Date;
4987
- status: "active" | "inactive" | "suspended";
4988
5117
  emailVerifiedAt: Date | null;
4989
5118
  phoneVerifiedAt: Date | null;
4990
5119
  lastLoginAt: Date | null;
@@ -5181,209 +5310,6 @@ declare function getAuthConfig(): AuthConfig;
5181
5310
  */
5182
5311
  declare function getSessionTtl(override?: string | number): number;
5183
5312
 
5184
- /**
5185
- * Google OAuth 2.0 Client
5186
- *
5187
- * Authorization Code Flow 구현
5188
- * - getGoogleAuthUrl: Google 로그인 URL 생성
5189
- * - exchangeCodeForTokens: Code를 Token으로 교환
5190
- * - getGoogleUserInfo: 사용자 정보 조회
5191
- */
5192
- interface GoogleTokenResponse {
5193
- access_token: string;
5194
- expires_in: number;
5195
- refresh_token?: string;
5196
- scope: string;
5197
- token_type: string;
5198
- id_token?: string;
5199
- }
5200
- interface GoogleUserInfo {
5201
- id: string;
5202
- email: string;
5203
- verified_email: boolean;
5204
- name?: string;
5205
- given_name?: string;
5206
- family_name?: string;
5207
- picture?: string;
5208
- locale?: string;
5209
- }
5210
- /**
5211
- * Google OAuth가 활성화되어 있는지 확인
5212
- */
5213
- declare function isGoogleOAuthEnabled(): boolean;
5214
- /**
5215
- * Google OAuth 설정 가져오기
5216
- */
5217
- declare function getGoogleOAuthConfig(): {
5218
- clientId: string;
5219
- clientSecret: string;
5220
- redirectUri: string;
5221
- };
5222
- /**
5223
- * Google 로그인 URL 생성
5224
- *
5225
- * @param state - CSRF 방지용 state 파라미터 (암호화된 returnUrl + nonce 포함)
5226
- * @param scopes - 요청할 OAuth scopes (기본: env 또는 email, profile)
5227
- */
5228
- declare function getGoogleAuthUrl(state: string, scopes?: string[]): string;
5229
- /**
5230
- * Authorization Code를 Token으로 교환
5231
- *
5232
- * @param code - Google에서 받은 authorization code
5233
- */
5234
- declare function exchangeCodeForTokens(code: string): Promise<GoogleTokenResponse>;
5235
- /**
5236
- * Access Token으로 Google 사용자 정보 조회
5237
- *
5238
- * @param accessToken - Google access token
5239
- */
5240
- declare function getGoogleUserInfo(accessToken: string): Promise<GoogleUserInfo>;
5241
- /**
5242
- * Refresh Token으로 새 Access Token 획득
5243
- *
5244
- * @param refreshToken - Google refresh token
5245
- */
5246
- declare function refreshAccessToken(refreshToken: string): Promise<GoogleTokenResponse>;
5247
-
5248
- /**
5249
- * OAuth State Management
5250
- *
5251
- * CSRF 방지를 위한 state 파라미터 암호화/복호화
5252
- * - returnUrl: OAuth 성공 후 리다이렉트할 URL
5253
- * - nonce: CSRF 방지용 일회용 토큰
5254
- * - provider: OAuth provider (google, github 등)
5255
- * - publicKey, keyId, fingerprint, algorithm: 클라이언트 키 정보
5256
- * - expiresAt: state 만료 시간
5257
- */
5258
-
5259
- interface OAuthState {
5260
- returnUrl: string;
5261
- nonce: string;
5262
- provider: string;
5263
- publicKey: string;
5264
- keyId: string;
5265
- fingerprint: string;
5266
- algorithm: KeyAlgorithmType;
5267
- metadata?: Record<string, unknown>;
5268
- }
5269
- interface CreateOAuthStateParams {
5270
- provider: string;
5271
- returnUrl: string;
5272
- publicKey: string;
5273
- keyId: string;
5274
- fingerprint: string;
5275
- algorithm: KeyAlgorithmType;
5276
- metadata?: Record<string, unknown>;
5277
- }
5278
- /**
5279
- * OAuth state 생성 및 암호화
5280
- *
5281
- * @param params - state 생성에 필요한 파라미터
5282
- * @returns 암호화된 state 문자열
5283
- */
5284
- declare function createOAuthState(params: CreateOAuthStateParams): Promise<string>;
5285
- /**
5286
- * OAuth state 복호화 및 검증
5287
- *
5288
- * @param encryptedState - 암호화된 state 문자열
5289
- * @returns 복호화된 state 객체
5290
- * @throws Error if state is invalid or expired (JWE exp claim으로 자동 검증)
5291
- */
5292
- declare function verifyOAuthState(encryptedState: string): Promise<OAuthState>;
5293
-
5294
- /**
5295
- * OAuth Provider 추상화
5296
- *
5297
- * Provider별로 하드코딩된 분기를 제거하기 위한 공통 인터페이스와 registry.
5298
- * - 내장 provider(google)는 패키지 로드 시점에 자기 등록(dogfood)
5299
- * - 외부 패키지(@superself/auth 등)는 registerOAuthProvider()로 런타임 등록
5300
- *
5301
- * @spfn/auth는 토큰 issuer가 아니라 소비(client) 측이므로,
5302
- * 이 추상화는 "authorize URL 생성 → code 교환 → 사용자 정보 정규화"까지만 다룬다.
5303
- */
5304
-
5305
- /**
5306
- * Provider 사용자 정보를 공통 형태로 정규화한 신원
5307
- *
5308
- * provider별 응답 형태(snake_case 등)를 service에 노출하지 않기 위한 경계.
5309
- */
5310
- interface NormalizedIdentity {
5311
- providerUserId: string;
5312
- email: string | null;
5313
- emailVerified: boolean;
5314
- name?: string;
5315
- avatar?: string;
5316
- }
5317
- /**
5318
- * 정규화된 OAuth 토큰 응답
5319
- *
5320
- * @property expiresIn - access token 만료까지 남은 초(seconds)
5321
- */
5322
- interface OAuthTokens {
5323
- accessToken: string;
5324
- refreshToken?: string;
5325
- expiresIn: number;
5326
- }
5327
- /**
5328
- * OAuth provider 구현 인터페이스
5329
- *
5330
- * google, superself 등 모든 provider가 이 형태를 만족해야 registry에 등록된다.
5331
- */
5332
- interface OAuthProvider {
5333
- id: SocialProvider;
5334
- /**
5335
- * provider가 사용 가능한 상태인지(필수 env 등) 확인
5336
- */
5337
- isEnabled(): boolean;
5338
- /**
5339
- * provider 로그인 페이지로 보낼 authorization URL 생성
5340
- *
5341
- * @param state - CSRF 방지용 암호화 state
5342
- * @param scopes - 요청할 scope (미지정 시 provider 기본값)
5343
- */
5344
- getAuthUrl(state: string, scopes?: string[]): string;
5345
- /**
5346
- * authorization code를 토큰으로 교환
5347
- */
5348
- exchangeCodeForTokens(code: string): Promise<OAuthTokens>;
5349
- /**
5350
- * access token으로 사용자 정보를 조회하고 공통 형태로 정규화
5351
- */
5352
- getUserInfo(accessToken: string): Promise<NormalizedIdentity>;
5353
- /**
5354
- * refresh token으로 access token 갱신 (provider가 지원하는 경우)
5355
- *
5356
- * 저장된 provider 토큰을 이후 API 호출에 재사용할 때 사용한다.
5357
- * 미구현 provider는 갱신 불가로 간주한다.
5358
- */
5359
- refreshTokens?(refreshToken: string): Promise<OAuthTokens>;
5360
- }
5361
- /**
5362
- * OAuth provider 등록 (public)
5363
- *
5364
- * 동일 id로 다시 등록하면 덮어쓴다(외부 패키지의 override 허용).
5365
- */
5366
- declare function registerOAuthProvider(provider: OAuthProvider): void;
5367
- /**
5368
- * 등록된 provider 조회. 미등록이면 undefined.
5369
- */
5370
- declare function getOAuthProvider(id: SocialProvider): OAuthProvider | undefined;
5371
- /**
5372
- * 등록된 모든 provider 목록
5373
- */
5374
- declare function getRegisteredProviders(): OAuthProvider[];
5375
-
5376
- /**
5377
- * Google OAuthProvider 구현
5378
- *
5379
- * 기존 google.ts의 함수를 OAuthProvider 인터페이스로 래핑한다.
5380
- * google.ts 자체는 그대로 유지(테스트·google 전용 route가 직접 의존).
5381
- *
5382
- * 이 모듈을 import 하는 것만으로 google provider가 registry에 자기 등록된다.
5383
- */
5384
-
5385
- declare const googleProvider: OAuthProvider;
5386
-
5387
5313
  /**
5388
5314
  * One-Time Token Manager
5389
5315
  *
@@ -5649,9 +5575,9 @@ declare const invitationCreatedEvent: _spfn_core_event.EventDef<{
5649
5575
  } | undefined;
5650
5576
  email: string;
5651
5577
  roleId: number;
5578
+ expiresAt: string;
5652
5579
  token: string;
5653
5580
  invitedBy: string;
5654
- expiresAt: string;
5655
5581
  invitationId: string;
5656
5582
  isResend: boolean;
5657
5583
  }>;
@@ -5686,4 +5612,4 @@ type AuthRegisterPayload = typeof authRegisterEvent._payload;
5686
5612
  type InvitationCreatedPayload = typeof invitationCreatedEvent._payload;
5687
5613
  type InvitationAcceptedPayload = typeof invitationAcceptedEvent._payload;
5688
5614
 
5689
- export { type AuthConfig, AuthContext, type AuthLifecycleConfig, type AuthLifecycleOptions, type AuthLoginPayload, type AuthMetadataEntity, AuthMetadataRepository, AuthProviderSchema, type AuthRegisterPayload, COOKIE_NAMES, type CreateOAuthStateParams, type GoogleTokenResponse, type GoogleUserInfo, type Invitation, type InvitationAcceptedPayload, type InvitationCreatedPayload, InvitationStatus, InvitationsRepository, KeyAlgorithmType, type KeyPair, KeysRepository, type NewAuthMetadataEntity, type NewInvitation, type NewPermission, type NewPermissionEntity, type NewRole, type NewRoleEntity, type NewRolePermission, type NewUser, type NewUserPermission, type NewUserProfile, type NewUserPublicKey, type NewUserSocialAccount, type NewVerificationCode, type NormalizedIdentity, type OAuthProvider, type OAuthState, type OAuthTokens, type Permission, type PermissionEntity, PermissionsRepository, type Role, type RoleEntity, type RoleGuardOptions, type RolePermission, RolePermissionsRepository, RolesRepository, type SessionPayload, SocialAccountsRepository, SocialProvider, type TokenPayload, type UpdateProfileParams, type User, type UserPermission, UserPermissionsRepository, type UserProfile, UserProfilesRepository, type UserPublicKey, type UserSocialAccount, UsersRepository, type VerificationCode, VerificationCodesRepository, VerificationPurpose, acceptInvitation, addPermissionToRole, authLogger, authLoginEvent, authMetadata, authMetadataRepository, authRegisterEvent, authSchema, cancelInvitation, checkUsernameAvailableService, configureAuth, createAuthLifecycle, createInvitation, createOAuthState, createRole, decodeToken, deleteInvitation, deleteRole, exchangeCodeForTokens, expireOldInvitations, generateClientToken, generateKeyPair, generateKeyPairES256, generateKeyPairRS256, generateToken, getAllRoles, getAuth, getAuthConfig, getAuthSessionService, getGoogleAuthUrl, getGoogleOAuthConfig, getGoogleUserInfo, getInvitationByToken, getInvitationWithDetails, getKeyId, getKeySize, getLocale, getOAuthProvider, getOneTimeTokenManager, getOptionalAuth, getRegisteredProviders, getRole, getRoleByName, getRolePermissions, getSessionTtl, getUser, getUserByEmailService, getUserByIdService, getUserByPhoneService, getUserId, getUserPermissions, getUserProfileService, getUserRole, googleProvider, hasAllPermissions, hasAnyPermission, hasAnyRole, hasPermission, hasRole, hashPassword, initOneTimeTokenManager, initializeAuth, invitationAcceptedEvent, invitationCreatedEvent, invitationsRepository, isGoogleOAuthEnabled, keysRepository, listInvitations, oneTimeTokenAuth, parseDuration, permissions, permissionsRepository, refreshAccessToken, registerOAuthProvider, removePermissionFromRole, requireAnyPermission, requirePermissions, requireRole, resendInvitation, roleGuard, rolePermissions, rolePermissionsRepository, roles, rolesRepository, setRolePermissions, shouldRotateKey, socialAccountsRepository, updateLastLoginService, updateLocaleService, updateRole, updateUserProfileService, updateUserService, updateUsernameService, userInvitations, userPermissions, userPermissionsRepository, userProfiles, userProfilesRepository, userPublicKeys, userSocialAccounts, users, usersRepository, validateInvitation, validatePasswordStrength, verificationCodes, verificationCodesRepository, verifyClientToken, verifyKeyFingerprint, verifyOAuthState, verifyPassword, verifyToken };
5615
+ export { type AuthConfig, AuthContext, type AuthLifecycleConfig, type AuthLifecycleOptions, type AuthLoginPayload, type AuthMetadataEntity, AuthMetadataRepository, AuthProviderSchema, type AuthRegisterPayload, COOKIE_NAMES, type CreateOAuthStateParams, type GoogleTokenResponse, type GoogleUserInfo, type Invitation, type InvitationAcceptedPayload, type InvitationCreatedPayload, InvitationStatus, InvitationsRepository, KeyAlgorithmType, type KeyPair, KeysRepository, type NewAuthMetadataEntity, type NewInvitation, type NewPermission, type NewPermissionEntity, type NewRole, type NewRoleEntity, type NewRolePermission, type NewUser, type NewUserPermission, type NewUserProfile, type NewUserPublicKey, type NewUserSocialAccount, type NewVerificationCode, OAuthProvider, type OAuthState, type Permission, type PermissionEntity, PermissionsRepository, type Role, type RoleEntity, type RoleGuardOptions, type RolePermission, RolePermissionsRepository, RolesRepository, type SessionPayload, SocialAccountsRepository, SocialProvider, type TokenPayload, type UpdateProfileParams, type User, type UserPermission, UserPermissionsRepository, type UserProfile, UserProfilesRepository, type UserPublicKey, type UserSocialAccount, UsersRepository, type VerificationCode, VerificationCodesRepository, VerificationPurpose, acceptInvitation, addPermissionToRole, authLogger, authLoginEvent, authMetadata, authMetadataRepository, authRegisterEvent, authSchema, cancelInvitation, checkUsernameAvailableService, configureAuth, createAuthLifecycle, createInvitation, createOAuthState, createRole, decodeToken, deleteInvitation, deleteRole, exchangeCodeForTokens, expireOldInvitations, generateClientToken, generateKeyPair, generateKeyPairES256, generateKeyPairRS256, generateToken, getAllRoles, getAuth, getAuthConfig, getAuthSessionService, getGoogleAuthUrl, getGoogleOAuthConfig, getGoogleUserInfo, getInvitationByToken, getInvitationWithDetails, getKeyId, getKeySize, getLocale, getOneTimeTokenManager, getOptionalAuth, getRole, getRoleByName, getRolePermissions, getSessionTtl, getUser, getUserByEmailService, getUserByIdService, getUserByPhoneService, getUserId, getUserPermissions, getUserProfileService, getUserRole, googleProvider, hasAllPermissions, hasAnyPermission, hasAnyRole, hasPermission, hasRole, hashPassword, initOneTimeTokenManager, initializeAuth, invitationAcceptedEvent, invitationCreatedEvent, invitationsRepository, isGoogleOAuthEnabled, keysRepository, listInvitations, oneTimeTokenAuth, parseDuration, permissions, permissionsRepository, refreshAccessToken, removePermissionFromRole, requireAnyPermission, requirePermissions, requireRole, resendInvitation, roleGuard, rolePermissions, rolePermissionsRepository, roles, rolesRepository, setRolePermissions, shouldRotateKey, socialAccountsRepository, updateLastLoginService, updateLocaleService, updateRole, updateUserProfileService, updateUserService, updateUsernameService, userInvitations, userPermissions, userPermissionsRepository, userProfiles, userProfilesRepository, userPublicKeys, userSocialAccounts, users, usersRepository, validateInvitation, validatePasswordStrength, verificationCodes, verificationCodesRepository, verifyClientToken, verifyKeyFingerprint, verifyOAuthState, verifyPassword, verifyToken };