@thinkingcat/auth-utils 1.0.11 → 1.0.13
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 +5 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ npm install @thinkingcat/auth-utils
|
|
|
60
60
|
```json
|
|
61
61
|
{
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@thinkingcat/auth-utils": "^1.0.
|
|
63
|
+
"@thinkingcat/auth-utils": "^1.0.12"
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
```
|
|
@@ -139,7 +139,7 @@ import {
|
|
|
139
139
|
createMiddlewareConfig,
|
|
140
140
|
handleMiddleware,
|
|
141
141
|
verifyAndRefreshTokenWithNextAuth,
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
// 라이센스
|
|
144
144
|
checkLicenseKey,
|
|
145
145
|
|
|
@@ -166,7 +166,8 @@ const response = await handleMiddleware(req, middlewareConfig, {
|
|
|
166
166
|
});
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
-
**중요**:
|
|
169
|
+
**중요**:
|
|
170
|
+
|
|
170
171
|
- 라이센스 키는 모든 함수 호출 시 필수 파라미터입니다.
|
|
171
172
|
- 라이센스 키가 없거나 유효하지 않으면 함수가 에러를 발생시킵니다.
|
|
172
173
|
- 라이센스 키는 SHA-256 해시로 변환되어 모듈 내부의 유효한 키 목록과 비교됩니다.
|
|
@@ -1307,7 +1308,7 @@ const response = await handleMiddleware(req, middlewareConfig, {
|
|
|
1307
1308
|
## 📦 패키지 정보
|
|
1308
1309
|
|
|
1309
1310
|
- **패키지명**: `@thinkingcat/auth-utils`
|
|
1310
|
-
- **버전**: `1.0.
|
|
1311
|
+
- **버전**: `1.0.12`
|
|
1311
1312
|
- **라이선스**: MIT
|
|
1312
1313
|
- **저장소**: npm registry
|
|
1313
1314
|
|
package/dist/index.d.ts
CHANGED
|
@@ -325,7 +325,7 @@ export interface MiddlewareOptions {
|
|
|
325
325
|
/** 라이센스 키 (필수) */
|
|
326
326
|
licenseKey: string;
|
|
327
327
|
}
|
|
328
|
-
export declare function checkLicenseKey(licenseKey: string): void
|
|
328
|
+
export declare function checkLicenseKey(licenseKey: string): Promise<void>;
|
|
329
329
|
export declare function checkRoleAccess(pathname: string, role: string, roleConfig: RoleAccessConfig): {
|
|
330
330
|
allowed: boolean;
|
|
331
331
|
message?: string;
|
package/dist/index.js
CHANGED
|
@@ -67,7 +67,14 @@ exports.handleMiddleware = handleMiddleware;
|
|
|
67
67
|
const jwt_1 = require("next-auth/jwt");
|
|
68
68
|
const jose_1 = require("jose");
|
|
69
69
|
const server_1 = require("next/server");
|
|
70
|
-
|
|
70
|
+
// Edge Runtime 호환을 위해 Web Crypto API 사용
|
|
71
|
+
async function createHashSHA256(data) {
|
|
72
|
+
const encoder = new TextEncoder();
|
|
73
|
+
const dataBuffer = encoder.encode(data);
|
|
74
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
|
|
75
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
76
|
+
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
77
|
+
}
|
|
71
78
|
/**
|
|
72
79
|
* 토큰 검증 및 디코딩
|
|
73
80
|
* @param accessToken JWT access token
|
|
@@ -331,7 +338,7 @@ function createRedirectHTML(redirectPath, text) {
|
|
|
331
338
|
* @returns NextResponse 객체
|
|
332
339
|
*/
|
|
333
340
|
async function createAuthResponse(accessToken, secret, options) {
|
|
334
|
-
checkLicenseKey(options.licenseKey);
|
|
341
|
+
await checkLicenseKey(options.licenseKey);
|
|
335
342
|
const { refreshToken, redirectPath, text, cookiePrefix, isProduction = false, cookieDomain, serviceId, } = options;
|
|
336
343
|
// 1. 토큰 검증
|
|
337
344
|
const tokenResult = await verifyToken(accessToken, secret);
|
|
@@ -600,11 +607,11 @@ function requiresSubscription(pathname, role, subscriptionRequiredPaths, systemA
|
|
|
600
607
|
const VALID_LICENSE_KEY_HASHES = new Set([
|
|
601
608
|
'73bce4f3b64804c255cdab450d759a8b53038f9edb59ae42d9988b08dfd007e2',
|
|
602
609
|
]);
|
|
603
|
-
function checkLicenseKey(licenseKey) {
|
|
610
|
+
async function checkLicenseKey(licenseKey) {
|
|
604
611
|
if (!licenseKey || licenseKey.length < 10) {
|
|
605
612
|
throw new Error('License key is required');
|
|
606
613
|
}
|
|
607
|
-
const keyHash =
|
|
614
|
+
const keyHash = await createHashSHA256(licenseKey);
|
|
608
615
|
if (!VALID_LICENSE_KEY_HASHES.has(keyHash)) {
|
|
609
616
|
throw new Error('Invalid license key');
|
|
610
617
|
}
|
|
@@ -858,7 +865,7 @@ async function handleMiddleware(req, config, options) {
|
|
|
858
865
|
try {
|
|
859
866
|
const pathname = req.nextUrl.pathname;
|
|
860
867
|
const { secret, isProduction, cookieDomain, getNextAuthToken, licenseKey } = options;
|
|
861
|
-
checkLicenseKey(licenseKey);
|
|
868
|
+
await checkLicenseKey(licenseKey);
|
|
862
869
|
if (!config.serviceId) {
|
|
863
870
|
throw new Error('serviceId is required in middleware config');
|
|
864
871
|
}
|