@thinkingcat/auth-utils 2.0.1 → 2.0.3
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/README.md +18 -24
- package/dist/middleware/handler.js +34 -0
- package/dist/utils/redirect.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ npm install @thinkingcat/auth-utils
|
|
|
91
91
|
```json
|
|
92
92
|
{
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@thinkingcat/auth-utils": "^
|
|
94
|
+
"@thinkingcat/auth-utils": "^2.0.2"
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
```
|
|
@@ -237,7 +237,7 @@ const response = await handleMiddleware(req, middlewareConfig, {
|
|
|
237
237
|
|
|
238
238
|
### 토큰 검증 및 생성
|
|
239
239
|
|
|
240
|
-
#### `verifyToken(accessToken: string, secret: string
|
|
240
|
+
#### `verifyToken(accessToken: string, secret: string)`
|
|
241
241
|
|
|
242
242
|
JWT access token을 검증하고 디코딩합니다.
|
|
243
243
|
|
|
@@ -245,7 +245,6 @@ JWT access token을 검증하고 디코딩합니다.
|
|
|
245
245
|
|
|
246
246
|
- `accessToken`: 검증할 JWT 토큰
|
|
247
247
|
- `secret`: JWT 서명에 사용할 secret key
|
|
248
|
-
- `licenseKey`: 라이센스 키 (필수)
|
|
249
248
|
|
|
250
249
|
**반환값:**
|
|
251
250
|
|
|
@@ -256,8 +255,7 @@ JWT access token을 검증하고 디코딩합니다.
|
|
|
256
255
|
|
|
257
256
|
```typescript
|
|
258
257
|
const secret = process.env.NEXTAUTH_SECRET!;
|
|
259
|
-
const
|
|
260
|
-
const result = await verifyToken(accessToken, secret, licenseKey);
|
|
258
|
+
const result = await verifyToken(accessToken, secret);
|
|
261
259
|
|
|
262
260
|
if (result) {
|
|
263
261
|
const { payload } = result;
|
|
@@ -1054,8 +1052,8 @@ export async function GET(req: NextRequest) {
|
|
|
1054
1052
|
}
|
|
1055
1053
|
|
|
1056
1054
|
const secret = process.env.NEXTAUTH_SECRET!;
|
|
1057
|
-
|
|
1058
|
-
const tokenResult = await verifyToken(tokenParam, secret
|
|
1055
|
+
|
|
1056
|
+
const tokenResult = await verifyToken(tokenParam, secret);
|
|
1059
1057
|
|
|
1060
1058
|
if (!tokenResult) {
|
|
1061
1059
|
return NextResponse.redirect("/login");
|
|
@@ -1096,8 +1094,8 @@ export async function GET(req: NextRequest) {
|
|
|
1096
1094
|
}
|
|
1097
1095
|
|
|
1098
1096
|
const secret = process.env.NEXTAUTH_SECRET!;
|
|
1099
|
-
|
|
1100
|
-
const tokenResult = await verifyToken(tokenParam, secret
|
|
1097
|
+
|
|
1098
|
+
const tokenResult = await verifyToken(tokenParam, secret);
|
|
1101
1099
|
|
|
1102
1100
|
if (!tokenResult) {
|
|
1103
1101
|
return NextResponse.redirect("/login");
|
|
@@ -1140,10 +1138,10 @@ export async function GET(req: NextRequest) {
|
|
|
1140
1138
|
}
|
|
1141
1139
|
|
|
1142
1140
|
const secret = process.env.NEXTAUTH_SECRET!;
|
|
1143
|
-
|
|
1141
|
+
|
|
1144
1142
|
const isProduction = process.env.NODE_ENV === "production";
|
|
1145
1143
|
|
|
1146
|
-
const tokenResult = await verifyToken(tokenParam, secret
|
|
1144
|
+
const tokenResult = await verifyToken(tokenParam, secret);
|
|
1147
1145
|
if (!tokenResult) {
|
|
1148
1146
|
return NextResponse.redirect("/login");
|
|
1149
1147
|
}
|
|
@@ -1490,31 +1488,27 @@ const response = await handleMiddleware(req, middlewareConfig, {
|
|
|
1490
1488
|
## 📦 패키지 정보
|
|
1491
1489
|
|
|
1492
1490
|
- **패키지명**: `@thinkingcat/auth-utils`
|
|
1493
|
-
- **버전**: `
|
|
1491
|
+
- **버전**: `2.0.2`
|
|
1494
1492
|
- **라이선스**: MIT
|
|
1495
1493
|
- **저장소**: npm registry
|
|
1496
1494
|
|
|
1497
1495
|
## 📝 변경 이력 (Changelog)
|
|
1498
1496
|
|
|
1499
|
-
###
|
|
1497
|
+
### v2.0.2 (2025-12-24)
|
|
1500
1498
|
|
|
1501
1499
|
**새로운 기능:**
|
|
1502
1500
|
|
|
1503
|
-
-
|
|
1504
|
-
-
|
|
1505
|
-
-
|
|
1501
|
+
- SSO 로그인 URL 경로 최적화 (`/login` -> `/auth/login`)
|
|
1502
|
+
- 라이센스 키(LICENSE_KEY) 필수화 및 가용성 확대
|
|
1503
|
+
- 타입 정의 및 미들웨어 핸들러의 안정성 강화
|
|
1506
1504
|
|
|
1507
1505
|
**개선 사항:**
|
|
1508
1506
|
|
|
1509
|
-
-
|
|
1510
|
-
-
|
|
1511
|
-
-
|
|
1512
|
-
- 불필요한 주석 제거
|
|
1513
|
-
|
|
1514
|
-
**성능 최적화:**
|
|
1507
|
+
- `verifyToken` 함수에서 `licenseKey` 파라미터 제거 (내부 로직 최적화)
|
|
1508
|
+
- `README.md`를 최신 소스 코드 API에 맞게 전체 업데이트
|
|
1509
|
+
- 미들웨어 설정(`MiddlewareConfig`) 및 옵션(`MiddlewareOptions`) 상세화
|
|
1515
1510
|
|
|
1516
|
-
|
|
1517
|
-
- 조건부 로깅으로 런타임 오버헤드 감소
|
|
1511
|
+
### v1.0.17 (2024-11-15)
|
|
1518
1512
|
|
|
1519
1513
|
## 🤝 기여 (Contributing)
|
|
1520
1514
|
|
|
@@ -71,6 +71,40 @@ async function handleMiddleware(req, config, options) {
|
|
|
71
71
|
(0, logger_js_1.debugLog)('handleMiddleware', 'getToken failed', error);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
// Refresh token 체크 - 없으면 모든 인증 쿠키 초기화
|
|
75
|
+
const refreshTokenCookieName = `${cookiePrefix}_refresh_token`;
|
|
76
|
+
const refreshTokenCookie = req.cookies.get(refreshTokenCookieName);
|
|
77
|
+
if (!refreshTokenCookie && req.cookies.getAll().length > 0) {
|
|
78
|
+
(0, logger_js_1.debugLog)('handleMiddleware', `No refresh token found (${refreshTokenCookieName}), clearing all auth cookies`);
|
|
79
|
+
// 인증 관련 쿠키 패턴
|
|
80
|
+
const authCookiePatterns = [
|
|
81
|
+
/^next-auth\./,
|
|
82
|
+
/^__Secure-next-auth\./,
|
|
83
|
+
/_access_token$/,
|
|
84
|
+
/_refresh_token$/,
|
|
85
|
+
/^auth-token$/,
|
|
86
|
+
/^__Secure-auth-token$/,
|
|
87
|
+
];
|
|
88
|
+
// 응답 생성하여 쿠키 삭제
|
|
89
|
+
const response = NextResponseClass.next();
|
|
90
|
+
// 모든 쿠키 확인하고 인증 관련 쿠키 삭제
|
|
91
|
+
req.cookies.getAll().forEach((cookie) => {
|
|
92
|
+
const isAuthCookie = authCookiePatterns.some((pattern) => pattern.test(cookie.name));
|
|
93
|
+
if (isAuthCookie) {
|
|
94
|
+
(0, logger_js_1.debugLog)('handleMiddleware', `Deleting stale cookie: ${cookie.name}`);
|
|
95
|
+
response.cookies.delete(cookie.name);
|
|
96
|
+
// 추가로 만료된 쿠키로 설정
|
|
97
|
+
response.cookies.set(cookie.name, '', {
|
|
98
|
+
expires: new Date(0),
|
|
99
|
+
path: '/',
|
|
100
|
+
secure: isProduction,
|
|
101
|
+
httpOnly: true,
|
|
102
|
+
sameSite: 'lax',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
(0, logger_js_1.debugLog)('handleMiddleware', 'Stale auth cookies cleared');
|
|
107
|
+
}
|
|
74
108
|
const effectiveRole = (0, roles_js_1.getEffectiveRole)(token, serviceId);
|
|
75
109
|
// 1. API 요청 처리
|
|
76
110
|
if (pathname.startsWith('/api/')) {
|
package/dist/utils/redirect.js
CHANGED
|
@@ -38,7 +38,7 @@ async function redirectToSSOLogin(req, serviceId, ssoBaseURL) {
|
|
|
38
38
|
const { NextResponse: NextResponseClass } = await (0, server_js_1.getNextServer)();
|
|
39
39
|
const baseUrl = ssoBaseURL || 'https://sso.thinkingcat.com';
|
|
40
40
|
const callbackUrl = encodeURIComponent(req.url);
|
|
41
|
-
return NextResponseClass.redirect(`${baseUrl}/login?serviceId=${serviceId}&callbackUrl=${callbackUrl}`);
|
|
41
|
+
return NextResponseClass.redirect(`${baseUrl}/auth/login?serviceId=${serviceId}&callbackUrl=${callbackUrl}`);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* 역할별 대시보드로 리다이렉트
|