@thinkingcat/auth-utils 2.0.8 → 2.0.10
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/core/jwt.d.ts +1 -1
- package/dist/core/jwt.js +9 -17
- package/dist/types/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/core/jwt.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare function extractRoleFromPayload(payload: JWTPayload, serviceId: s
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function createNextAuthJWT(payload: JWTPayload, serviceId: string): JWT;
|
|
17
17
|
/**
|
|
18
|
-
* NextAuth JWT를 인코딩된 세션 토큰으로 변환
|
|
18
|
+
* NextAuth JWT를 인코딩된 세션 토큰으로 변환
|
|
19
19
|
*/
|
|
20
20
|
export declare function encodeNextAuthToken(jwt: JWT, secret: string, maxAge?: number): Promise<string>;
|
|
21
21
|
/**
|
package/dist/core/jwt.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.isTokenExpired = isTokenExpired;
|
|
|
41
41
|
exports.isValidToken = isValidToken;
|
|
42
42
|
const jose_1 = require("jose");
|
|
43
43
|
const logger_js_1 = require("../utils/logger.js");
|
|
44
|
+
const crypto_js_1 = require("../utils/crypto.js");
|
|
44
45
|
/**
|
|
45
46
|
* 토큰 검증 및 디코딩
|
|
46
47
|
*/
|
|
@@ -115,7 +116,7 @@ function createNextAuthJWT(payload, serviceId) {
|
|
|
115
116
|
return jwt;
|
|
116
117
|
}
|
|
117
118
|
/**
|
|
118
|
-
* NextAuth JWT를 인코딩된 세션 토큰으로 변환
|
|
119
|
+
* NextAuth JWT를 인코딩된 세션 토큰으로 변환
|
|
119
120
|
*/
|
|
120
121
|
async function encodeNextAuthToken(jwt, secret, maxAge = 30 * 24 * 60 * 60) {
|
|
121
122
|
try {
|
|
@@ -129,23 +130,14 @@ async function encodeNextAuthToken(jwt, secret, maxAge = 30 * 24 * 60 * 60) {
|
|
|
129
130
|
return encoded;
|
|
130
131
|
}
|
|
131
132
|
catch (error) {
|
|
132
|
-
(0, logger_js_1.debugLog)('encodeNextAuthToken', 'NextAuth encode failed, using jose EncryptJWT fallback
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
(0, logger_js_1.debugLog)('encodeNextAuthToken', 'NextAuth encode failed, using jose EncryptJWT fallback', error);
|
|
134
|
+
const secretHash = await (0, crypto_js_1.createHashSHA256)(secret);
|
|
135
|
+
const keyBytes = new Uint8Array(32);
|
|
136
|
+
for (let i = 0; i < 32; i++) {
|
|
137
|
+
keyBytes[i] = parseInt(secretHash.slice(i * 2, i * 2 + 2), 16);
|
|
138
|
+
}
|
|
135
139
|
const now = Math.floor(Date.now() / 1000);
|
|
136
140
|
try {
|
|
137
|
-
// Web Crypto API를 이용한 HKDF 구현
|
|
138
|
-
const encoder = new TextEncoder();
|
|
139
|
-
const secretKey = await crypto.subtle.importKey('raw', encoder.encode(secret), 'HKDF', false, ['deriveKey']);
|
|
140
|
-
const derivedKey = await crypto.subtle.deriveKey({
|
|
141
|
-
name: 'HKDF',
|
|
142
|
-
hash: 'SHA-256',
|
|
143
|
-
salt: encoder.encode(''),
|
|
144
|
-
info: encoder.encode('NextAuth.js Generated Encryption Key'),
|
|
145
|
-
}, secretKey, { name: 'AES-GCM', length: 256 }, true, ['encrypt']);
|
|
146
|
-
// 유도된 키를 Uint8Array로 변환
|
|
147
|
-
const exportedKey = await crypto.subtle.exportKey('raw', derivedKey);
|
|
148
|
-
const keyBytes = new Uint8Array(exportedKey);
|
|
149
141
|
const token = await new jose_1.EncryptJWT(jwt)
|
|
150
142
|
.setProtectedHeader({
|
|
151
143
|
alg: 'dir',
|
|
@@ -158,7 +150,7 @@ async function encodeNextAuthToken(jwt, secret, maxAge = 30 * 24 * 60 * 60) {
|
|
|
158
150
|
return token;
|
|
159
151
|
}
|
|
160
152
|
catch (encryptError) {
|
|
161
|
-
(0, logger_js_1.debugError)('encodeNextAuthToken', '
|
|
153
|
+
(0, logger_js_1.debugError)('encodeNextAuthToken', 'EncryptJWT also failed:', encryptError);
|
|
162
154
|
throw new Error(`Failed to encode NextAuth token: ${error instanceof Error ? error.message : String(error)}`);
|
|
163
155
|
}
|
|
164
156
|
}
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED