@tern-secure/backend 1.2.0-canary.v20250919134427 → 1.2.0-canary.v20251002175916
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/auth/package.json +5 -0
- package/dist/admin/index.d.ts +1 -1
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +200 -182
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +23 -489
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/nextSessionTernSecure.d.ts.map +1 -1
- package/dist/admin/sessionTernSecure.d.ts +27 -5
- package/dist/admin/sessionTernSecure.d.ts.map +1 -1
- package/dist/auth/getauth.d.ts +15 -0
- package/dist/auth/getauth.d.ts.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +694 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/index.mjs +53 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/{chunk-ZIO4EKS5.mjs → chunk-4SGWLAJG.mjs} +8 -31
- package/dist/chunk-4SGWLAJG.mjs.map +1 -0
- package/dist/chunk-NEPV6OWI.mjs +550 -0
- package/dist/chunk-NEPV6OWI.mjs.map +1 -0
- package/dist/chunk-YKIA5EBF.mjs +142 -0
- package/dist/chunk-YKIA5EBF.mjs.map +1 -0
- package/dist/constants.d.ts +4 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/fireRestApi/createFireApi.d.ts +12 -0
- package/dist/fireRestApi/createFireApi.d.ts.map +1 -0
- package/dist/fireRestApi/emulator.d.ts +4 -0
- package/dist/fireRestApi/emulator.d.ts.map +1 -0
- package/dist/fireRestApi/endpointUrl.d.ts +6 -0
- package/dist/fireRestApi/endpointUrl.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/AbstractApi.d.ts +7 -0
- package/dist/fireRestApi/endpoints/AbstractApi.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/EmailApi.d.ts +14 -0
- package/dist/fireRestApi/endpoints/EmailApi.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/PasswordApi.d.ts +20 -0
- package/dist/fireRestApi/endpoints/PasswordApi.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/SignInTokenApi.d.ts +11 -0
- package/dist/fireRestApi/endpoints/SignInTokenApi.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/SignUpApi.d.ts +11 -0
- package/dist/fireRestApi/endpoints/SignUpApi.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/TokenApi.d.ts +21 -0
- package/dist/fireRestApi/endpoints/TokenApi.d.ts.map +1 -0
- package/dist/fireRestApi/endpoints/index.d.ts +6 -0
- package/dist/fireRestApi/endpoints/index.d.ts.map +1 -0
- package/dist/fireRestApi/index.d.ts +2 -0
- package/dist/fireRestApi/index.d.ts.map +1 -0
- package/dist/fireRestApi/request.d.ts +34 -0
- package/dist/fireRestApi/request.d.ts.map +1 -0
- package/dist/fireRestApi/resources/JSON.d.ts +50 -0
- package/dist/fireRestApi/resources/JSON.d.ts.map +1 -0
- package/dist/fireRestApi/resources/Token.d.ts +13 -0
- package/dist/fireRestApi/resources/Token.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +271 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -179
- package/dist/index.mjs.map +1 -1
- package/dist/instance/backendFireInstance.d.ts +4 -4
- package/dist/instance/backendFireInstance.d.ts.map +1 -1
- package/dist/instance/backendInstanceEdge.d.ts +2 -2
- package/dist/instance/backendInstanceEdge.d.ts.map +1 -1
- package/dist/tokens/authstate.d.ts +1 -1
- package/dist/tokens/authstate.d.ts.map +1 -1
- package/dist/tokens/keys.d.ts.map +1 -1
- package/dist/tokens/request.d.ts +3 -3
- package/dist/tokens/request.d.ts.map +1 -1
- package/dist/tokens/requestFire.d.ts.map +1 -1
- package/dist/tokens/types.d.ts +5 -2
- package/dist/tokens/types.d.ts.map +1 -1
- package/dist/utils/options.d.ts +1 -1
- package/dist/utils/options.d.ts.map +1 -1
- package/package.json +14 -3
- package/dist/admin/gemini.sessionTernSecure.d.ts +0 -8
- package/dist/admin/gemini.sessionTernSecure.d.ts.map +0 -1
- package/dist/chunk-ZIO4EKS5.mjs.map +0 -1
package/dist/admin/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createSessionCookie, clearSessionCookie } from './sessionTernSecure';
|
|
1
|
+
export { createSessionCookie, createCustomTokenClaims, clearSessionCookie } from './sessionTernSecure';
|
|
2
2
|
export { adminTernSecureAuth, adminTernSecureDb, TernSecureTenantManager } from '../utils/admin-init';
|
|
3
3
|
export { initializeAdminConfig } from '../utils/config';
|
|
4
4
|
export { createTenant, createTenantUser } from './tenant';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,kBAAkB,EACrB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACH,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EAC1B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EACH,uBAAuB,EACvB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACzB,MAAM,yBAAyB,CAAA;AAEhC,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EACrB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACH,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EAC1B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EACH,uBAAuB,EACvB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACzB,MAAM,yBAAyB,CAAA;AAEhC,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA"}
|
package/dist/admin/index.js
CHANGED
|
@@ -44,6 +44,7 @@ __export(admin_exports, {
|
|
|
44
44
|
authenticateRequest: () => authenticateRequest,
|
|
45
45
|
clearSessionCookie: () => clearSessionCookie,
|
|
46
46
|
createBackendInstance: () => createBackendInstance,
|
|
47
|
+
createCustomTokenClaims: () => createCustomTokenClaims,
|
|
47
48
|
createSessionCookie: () => createSessionCookie,
|
|
48
49
|
createTenant: () => createTenant,
|
|
49
50
|
createTenantUser: () => createTenantUser,
|
|
@@ -55,24 +56,65 @@ module.exports = __toCommonJS(admin_exports);
|
|
|
55
56
|
// src/admin/sessionTernSecure.ts
|
|
56
57
|
var import_errors = require("@tern-secure/shared/errors");
|
|
57
58
|
|
|
58
|
-
// src/
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
// src/constants.ts
|
|
60
|
+
var MAX_CACHE_LAST_UPDATED_AT_SECONDS = 5 * 60;
|
|
61
|
+
var DEFAULT_CACHE_DURATION = 3600 * 1e3;
|
|
62
|
+
var Attributes = {
|
|
63
|
+
AuthToken: "__ternsecureAuthToken",
|
|
64
|
+
AuthSignature: "__ternsecureAuthSignature",
|
|
65
|
+
AuthStatus: "__ternsecureAuthStatus",
|
|
66
|
+
AuthReason: "__ternsecureAuthReason",
|
|
67
|
+
AuthMessage: "__ternsecureAuthMessage",
|
|
68
|
+
TernSecureUrl: "__ternsecureUrl"
|
|
67
69
|
};
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
var Cookies = {
|
|
71
|
+
Session: "__session",
|
|
72
|
+
CsrfToken: "__session_terncf",
|
|
73
|
+
IdToken: "FIREBASE_[DEFAULT]",
|
|
74
|
+
Refresh: "FIREBASEID_[DEFAULT]",
|
|
75
|
+
Custom: "__custom",
|
|
76
|
+
Handshake: "__ternsecure_handshake",
|
|
77
|
+
DevBrowser: "__ternsecure_db_jwt",
|
|
78
|
+
RedirectCount: "__ternsecure_redirect_count",
|
|
79
|
+
HandshakeNonce: "__ternsecure_handshake_nonce"
|
|
80
|
+
};
|
|
81
|
+
var Headers2 = {
|
|
82
|
+
Accept: "accept",
|
|
83
|
+
AuthMessage: "x-ternsecure-auth-message",
|
|
84
|
+
Authorization: "authorization",
|
|
85
|
+
AuthReason: "x-ternsecure-auth-reason",
|
|
86
|
+
AuthSignature: "x-ternsecure-auth-signature",
|
|
87
|
+
AuthStatus: "x-ternsecure-auth-status",
|
|
88
|
+
AuthToken: "x-ternsecure-auth-token",
|
|
89
|
+
CacheControl: "cache-control",
|
|
90
|
+
TernSecureRedirectTo: "x-ternsecure-redirect-to",
|
|
91
|
+
TernSecureRequestData: "x-ternsecure-request-data",
|
|
92
|
+
TernSecureUrl: "x-ternsecure-url",
|
|
93
|
+
CloudFrontForwardedProto: "cloudfront-forwarded-proto",
|
|
94
|
+
ContentType: "content-type",
|
|
95
|
+
ContentSecurityPolicy: "content-security-policy",
|
|
96
|
+
ContentSecurityPolicyReportOnly: "content-security-policy-report-only",
|
|
97
|
+
EnableDebug: "x-ternsecure-debug",
|
|
98
|
+
ForwardedHost: "x-forwarded-host",
|
|
99
|
+
ForwardedPort: "x-forwarded-port",
|
|
100
|
+
ForwardedProto: "x-forwarded-proto",
|
|
101
|
+
Host: "host",
|
|
102
|
+
Location: "location",
|
|
103
|
+
Nonce: "x-nonce",
|
|
104
|
+
Origin: "origin",
|
|
105
|
+
Referrer: "referer",
|
|
106
|
+
SecFetchDest: "sec-fetch-dest",
|
|
107
|
+
UserAgent: "user-agent",
|
|
108
|
+
ReportingEndpoints: "reporting-endpoints"
|
|
109
|
+
};
|
|
110
|
+
var ContentTypes = {
|
|
111
|
+
Json: "application/json"
|
|
112
|
+
};
|
|
113
|
+
var constants = {
|
|
114
|
+
Attributes,
|
|
115
|
+
Cookies,
|
|
116
|
+
Headers: Headers2,
|
|
117
|
+
ContentTypes
|
|
76
118
|
};
|
|
77
119
|
|
|
78
120
|
// src/utils/admin-init.ts
|
|
@@ -154,108 +196,128 @@ var COOKIE_OPTIONS = {
|
|
|
154
196
|
sameSite: "strict",
|
|
155
197
|
path: "/"
|
|
156
198
|
};
|
|
199
|
+
var DEFAULT_COOKIE_CONFIG = {
|
|
200
|
+
DEFAULT_EXPIRES_IN_MS: 5 * 60 * 1e3,
|
|
201
|
+
// 5 minutes
|
|
202
|
+
DEFAULT_EXPIRES_IN_SECONDS: 5 * 60,
|
|
203
|
+
REVOKE_REFRESH_TOKENS_ON_SIGNOUT: true
|
|
204
|
+
};
|
|
205
|
+
var DEFAULT_COOKIE_OPTIONS = {
|
|
206
|
+
httpOnly: true,
|
|
207
|
+
secure: process.env.NODE_ENV === "production",
|
|
208
|
+
sameSite: "strict",
|
|
209
|
+
path: "/"
|
|
210
|
+
};
|
|
211
|
+
var getCookieName = (baseName, prefix) => {
|
|
212
|
+
return prefix ? `${prefix}${baseName}` : baseName;
|
|
213
|
+
};
|
|
214
|
+
var createCookieOptions = (maxAge, overrides) => {
|
|
215
|
+
return {
|
|
216
|
+
maxAge,
|
|
217
|
+
httpOnly: overrides?.httpOnly ?? DEFAULT_COOKIE_OPTIONS.httpOnly,
|
|
218
|
+
secure: overrides?.secure ?? DEFAULT_COOKIE_OPTIONS.secure,
|
|
219
|
+
sameSite: overrides?.sameSite ?? DEFAULT_COOKIE_OPTIONS.sameSite,
|
|
220
|
+
path: overrides?.path ?? DEFAULT_COOKIE_OPTIONS.path
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
var getCookiePrefix = () => {
|
|
224
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
225
|
+
return isProduction ? "__HOST-" : "__dev_";
|
|
226
|
+
};
|
|
157
227
|
async function createSessionCookie(params, cookieStore, options) {
|
|
158
228
|
try {
|
|
159
|
-
const tenantAuth = getAuthForTenant(options?.tenantId);
|
|
160
|
-
const sessionConfig = getSessionConfig(options);
|
|
161
|
-
const cookieOptions = getCookieOptions(options);
|
|
162
|
-
let decodedToken;
|
|
163
|
-
let sessionCookie;
|
|
229
|
+
const tenantAuth = getAuthForTenant(options?.tenantId || "");
|
|
164
230
|
const idToken = typeof params === "string" ? params : params.idToken;
|
|
231
|
+
const refreshToken = typeof params === "string" ? void 0 : params.refreshToken;
|
|
165
232
|
if (!idToken) {
|
|
166
|
-
const error = new Error("ID token is required for session creation");
|
|
167
|
-
console.error("[createSessionCookie] Missing ID token:", error);
|
|
168
233
|
return {
|
|
169
234
|
success: false,
|
|
170
235
|
message: "ID token is required",
|
|
171
|
-
error: "INVALID_TOKEN"
|
|
172
|
-
cookieSet: false
|
|
236
|
+
error: "INVALID_TOKEN"
|
|
173
237
|
};
|
|
174
238
|
}
|
|
239
|
+
let decodedToken;
|
|
175
240
|
try {
|
|
176
|
-
console.log("Verifying ID token for tenant:", options?.tenantId);
|
|
177
241
|
decodedToken = await tenantAuth.verifyIdToken(idToken);
|
|
178
242
|
} catch (verifyError) {
|
|
179
|
-
console.error(
|
|
180
|
-
"[createSessionCookie] ID token verification failed:",
|
|
181
|
-
verifyError
|
|
182
|
-
);
|
|
183
243
|
const authError = (0, import_errors.handleFirebaseAuthError)(verifyError);
|
|
184
244
|
return {
|
|
185
245
|
success: false,
|
|
186
246
|
message: authError.message,
|
|
187
|
-
error: authError.code
|
|
188
|
-
cookieSet: false
|
|
247
|
+
error: authError.code
|
|
189
248
|
};
|
|
190
249
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
console.error(
|
|
210
|
-
"[createSessionCookie] Firebase session cookie creation failed:",
|
|
211
|
-
sessionError
|
|
250
|
+
const cookiePromises = [];
|
|
251
|
+
const cookiePrefix = getCookiePrefix();
|
|
252
|
+
const idTokenCookieName = getCookieName(constants.Cookies.IdToken, cookiePrefix);
|
|
253
|
+
cookiePromises.push(
|
|
254
|
+
cookieStore.set(
|
|
255
|
+
idTokenCookieName,
|
|
256
|
+
idToken,
|
|
257
|
+
createCookieOptions(DEFAULT_COOKIE_CONFIG.DEFAULT_EXPIRES_IN_SECONDS)
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
if (refreshToken) {
|
|
261
|
+
const refreshTokenCookieName = getCookieName(constants.Cookies.Refresh, cookiePrefix);
|
|
262
|
+
cookiePromises.push(
|
|
263
|
+
cookieStore.set(
|
|
264
|
+
refreshTokenCookieName,
|
|
265
|
+
refreshToken,
|
|
266
|
+
createCookieOptions(DEFAULT_COOKIE_CONFIG.DEFAULT_EXPIRES_IN_SECONDS)
|
|
267
|
+
)
|
|
212
268
|
);
|
|
213
|
-
const authError = (0, import_errors.handleFirebaseAuthError)(sessionError);
|
|
214
|
-
return {
|
|
215
|
-
success: false,
|
|
216
|
-
message: authError.message,
|
|
217
|
-
error: authError.code,
|
|
218
|
-
cookieSet: false
|
|
219
|
-
};
|
|
220
269
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
270
|
+
if (options?.cookies?.session) {
|
|
271
|
+
const sessionOptions = options.cookies.session;
|
|
272
|
+
const sessionCookieName = getCookieName(constants.Cookies.Session);
|
|
273
|
+
const expiresIn = sessionOptions.maxAge ? sessionOptions.maxAge * 1e3 : DEFAULT_COOKIE_CONFIG.DEFAULT_EXPIRES_IN_MS;
|
|
274
|
+
try {
|
|
275
|
+
const sessionCookie = await tenantAuth.createSessionCookie(idToken, { expiresIn });
|
|
276
|
+
cookiePromises.push(
|
|
277
|
+
cookieStore.set(
|
|
278
|
+
sessionCookieName,
|
|
279
|
+
sessionCookie,
|
|
280
|
+
createCookieOptions(
|
|
281
|
+
sessionOptions.maxAge || DEFAULT_COOKIE_CONFIG.DEFAULT_EXPIRES_IN_SECONDS,
|
|
282
|
+
{
|
|
283
|
+
httpOnly: sessionOptions.httpOnly,
|
|
284
|
+
sameSite: sessionOptions.sameSite,
|
|
285
|
+
path: sessionOptions.path
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
)
|
|
289
|
+
);
|
|
290
|
+
} catch (sessionError) {
|
|
233
291
|
console.error(
|
|
234
|
-
"[createSessionCookie]
|
|
235
|
-
|
|
292
|
+
"[createSessionCookie] Firebase session cookie creation failed:",
|
|
293
|
+
sessionError
|
|
236
294
|
);
|
|
237
|
-
|
|
295
|
+
const authError = (0, import_errors.handleFirebaseAuthError)(sessionError);
|
|
296
|
+
return {
|
|
297
|
+
success: false,
|
|
298
|
+
message: authError.message,
|
|
299
|
+
error: authError.code
|
|
300
|
+
};
|
|
238
301
|
}
|
|
239
|
-
} catch (cookieError) {
|
|
240
|
-
console.error(
|
|
241
|
-
"[createSessionCookie] Failed to set session cookie:",
|
|
242
|
-
cookieError
|
|
243
|
-
);
|
|
244
|
-
return {
|
|
245
|
-
success: false,
|
|
246
|
-
message: "Failed to set session cookie",
|
|
247
|
-
error: "COOKIE_SET_FAILED",
|
|
248
|
-
cookieSet: false
|
|
249
|
-
};
|
|
250
302
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
303
|
+
if (options?.enableCustomToken && decodedToken?.uid) {
|
|
304
|
+
const customTokenCookieName = getCookieName(constants.Cookies.Custom, cookiePrefix);
|
|
305
|
+
const customToken = await createCustomToken(decodedToken.uid, options);
|
|
306
|
+
if (customToken) {
|
|
307
|
+
cookiePromises.push(
|
|
308
|
+
cookieStore.set(
|
|
309
|
+
customTokenCookieName,
|
|
310
|
+
customToken,
|
|
311
|
+
createCookieOptions(DEFAULT_COOKIE_CONFIG.DEFAULT_EXPIRES_IN_SECONDS)
|
|
312
|
+
)
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
await Promise.all(cookiePromises);
|
|
254
317
|
return {
|
|
255
318
|
success: true,
|
|
256
319
|
message: "Session created successfully",
|
|
257
|
-
expiresIn:
|
|
258
|
-
cookieSet: cookieSetSuccessfully
|
|
320
|
+
expiresIn: DEFAULT_COOKIE_CONFIG.DEFAULT_EXPIRES_IN_SECONDS
|
|
259
321
|
};
|
|
260
322
|
} catch (error) {
|
|
261
323
|
console.error("[createSessionCookie] Unexpected error:", error);
|
|
@@ -263,51 +325,69 @@ async function createSessionCookie(params, cookieStore, options) {
|
|
|
263
325
|
return {
|
|
264
326
|
success: false,
|
|
265
327
|
message: authError.message || "Failed to create session",
|
|
266
|
-
error: authError.code || "INTERNAL_ERROR"
|
|
267
|
-
cookieSet: false
|
|
328
|
+
error: authError.code || "INTERNAL_ERROR"
|
|
268
329
|
};
|
|
269
330
|
}
|
|
270
331
|
}
|
|
271
332
|
async function clearSessionCookie(cookieStore, options) {
|
|
272
333
|
try {
|
|
273
|
-
const adminAuth = getAuthForTenant(options?.tenantId);
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
await cookieStore.
|
|
277
|
-
|
|
278
|
-
if (
|
|
334
|
+
const adminAuth = getAuthForTenant(options?.tenantId || "");
|
|
335
|
+
const cookiePrefix = getCookiePrefix();
|
|
336
|
+
const sessionCookieName = getCookieName(constants.Cookies.Session, cookiePrefix);
|
|
337
|
+
const sessionCookie = await cookieStore.get(sessionCookieName);
|
|
338
|
+
const deletionPromises = [];
|
|
339
|
+
if (options?.cookies?.session) {
|
|
340
|
+
deletionPromises.push(cookieStore.delete(sessionCookieName));
|
|
341
|
+
}
|
|
342
|
+
const idTokenCookieName = getCookieName(constants.Cookies.IdToken, cookiePrefix);
|
|
343
|
+
deletionPromises.push(cookieStore.delete(idTokenCookieName));
|
|
344
|
+
const refreshTokenCookieName = getCookieName(constants.Cookies.Refresh, cookiePrefix);
|
|
345
|
+
deletionPromises.push(cookieStore.delete(refreshTokenCookieName));
|
|
346
|
+
const customTokenCookieName = getCookieName(constants.Cookies.Custom, cookiePrefix);
|
|
347
|
+
deletionPromises.push(cookieStore.delete(customTokenCookieName));
|
|
348
|
+
deletionPromises.push(cookieStore.delete(constants.Cookies.Session));
|
|
349
|
+
await Promise.all(deletionPromises);
|
|
350
|
+
if (DEFAULT_COOKIE_CONFIG.REVOKE_REFRESH_TOKENS_ON_SIGNOUT && sessionCookie?.value) {
|
|
279
351
|
try {
|
|
280
|
-
const decodedClaims = await adminAuth.verifySessionCookie(
|
|
281
|
-
sessionCookie.value
|
|
282
|
-
);
|
|
352
|
+
const decodedClaims = await adminAuth.verifySessionCookie(sessionCookie.value);
|
|
283
353
|
await adminAuth.revokeRefreshTokens(decodedClaims.sub);
|
|
284
|
-
console.log(
|
|
285
|
-
`[clearSessionCookie] Successfully revoked tokens for user: ${decodedClaims.sub}`
|
|
286
|
-
);
|
|
287
354
|
} catch (revokeError) {
|
|
288
|
-
console.error(
|
|
289
|
-
"[clearSessionCookie] Failed to revoke refresh tokens:",
|
|
290
|
-
revokeError
|
|
291
|
-
);
|
|
355
|
+
console.error("[clearSessionCookie] Failed to revoke refresh tokens:", revokeError);
|
|
292
356
|
}
|
|
293
357
|
}
|
|
294
|
-
console.log("[clearSessionCookie] Session cookies cleared successfully");
|
|
295
358
|
return {
|
|
296
359
|
success: true,
|
|
297
|
-
message: "Session cleared successfully"
|
|
298
|
-
cookieSet: false
|
|
360
|
+
message: "Session cleared successfully"
|
|
299
361
|
};
|
|
300
362
|
} catch (error) {
|
|
301
|
-
console.error("[clearSessionCookie] Unexpected error:", error);
|
|
302
363
|
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
303
364
|
return {
|
|
304
365
|
success: false,
|
|
305
366
|
message: authError.message || "Failed to clear session",
|
|
306
|
-
error: authError.code || "INTERNAL_ERROR"
|
|
307
|
-
cookieSet: false
|
|
367
|
+
error: authError.code || "INTERNAL_ERROR"
|
|
308
368
|
};
|
|
309
369
|
}
|
|
310
370
|
}
|
|
371
|
+
async function createCustomToken(uid, options) {
|
|
372
|
+
const adminAuth = getAuthForTenant(options?.tenantId || "");
|
|
373
|
+
try {
|
|
374
|
+
const customToken = await adminAuth.createCustomToken(uid);
|
|
375
|
+
return customToken;
|
|
376
|
+
} catch (error) {
|
|
377
|
+
console.error("[createCustomToken] Error creating custom token:", error);
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async function createCustomTokenClaims(uid, developerClaims) {
|
|
382
|
+
const adminAuth = getAuthForTenant();
|
|
383
|
+
try {
|
|
384
|
+
const customToken = await adminAuth.createCustomToken(uid, developerClaims);
|
|
385
|
+
return customToken;
|
|
386
|
+
} catch (error) {
|
|
387
|
+
console.error("[createCustomToken] Error creating custom token:", error);
|
|
388
|
+
return "";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
311
391
|
|
|
312
392
|
// src/admin/tenant.ts
|
|
313
393
|
async function createTenant(displayName, emailSignInConfig, multiFactorConfig) {
|
|
@@ -352,7 +432,7 @@ async function createTenantUser(email, password, tenantId) {
|
|
|
352
432
|
var import_errors2 = require("@tern-secure/shared/errors");
|
|
353
433
|
var import_headers = require("next/headers");
|
|
354
434
|
var SESSION_CONSTANTS2 = {
|
|
355
|
-
COOKIE_NAME:
|
|
435
|
+
COOKIE_NAME: constants.Cookies.Session,
|
|
356
436
|
DEFAULT_EXPIRES_IN_MS: 60 * 60 * 24 * 5 * 1e3,
|
|
357
437
|
// 5 days
|
|
358
438
|
DEFAULT_EXPIRES_IN_SECONDS: 60 * 60 * 24 * 5,
|
|
@@ -365,7 +445,7 @@ async function CreateNextSessionCookie(idToken) {
|
|
|
365
445
|
expiresIn
|
|
366
446
|
});
|
|
367
447
|
const cookieStore = await (0, import_headers.cookies)();
|
|
368
|
-
cookieStore.set(
|
|
448
|
+
cookieStore.set(constants.Cookies.Session, sessionCookie, {
|
|
369
449
|
maxAge: expiresIn,
|
|
370
450
|
httpOnly: true,
|
|
371
451
|
secure: process.env.NODE_ENV === "production",
|
|
@@ -491,8 +571,7 @@ async function ClearNextSessionCookie(tenantId) {
|
|
|
491
571
|
const cookieStore = await (0, import_headers.cookies)();
|
|
492
572
|
const sessionCookie = cookieStore.get(SESSION_CONSTANTS2.COOKIE_NAME);
|
|
493
573
|
cookieStore.delete(SESSION_CONSTANTS2.COOKIE_NAME);
|
|
494
|
-
cookieStore.delete(
|
|
495
|
-
cookieStore.delete("_session");
|
|
574
|
+
cookieStore.delete(constants.Cookies.IdToken);
|
|
496
575
|
if (SESSION_CONSTANTS2.REVOKE_REFRESH_TOKENS_ON_SIGNOUT && sessionCookie?.value) {
|
|
497
576
|
try {
|
|
498
577
|
const decodedClaims = await tenantAuth.verifySessionCookie(
|
|
@@ -519,68 +598,6 @@ async function ClearNextSessionCookie(tenantId) {
|
|
|
519
598
|
// src/tokens/ternSecureRequest.ts
|
|
520
599
|
var import_cookie = require("cookie");
|
|
521
600
|
|
|
522
|
-
// src/constants.ts
|
|
523
|
-
var MAX_CACHE_LAST_UPDATED_AT_SECONDS = 5 * 60;
|
|
524
|
-
var DEFAULT_CACHE_DURATION = 3600 * 1e3;
|
|
525
|
-
var Attributes = {
|
|
526
|
-
AuthToken: "__ternsecureAuthToken",
|
|
527
|
-
AuthSignature: "__ternsecureAuthSignature",
|
|
528
|
-
AuthStatus: "__ternsecureAuthStatus",
|
|
529
|
-
AuthReason: "__ternsecureAuthReason",
|
|
530
|
-
AuthMessage: "__ternsecureAuthMessage",
|
|
531
|
-
TernSecureUrl: "__ternsecureUrl"
|
|
532
|
-
};
|
|
533
|
-
var Cookies = {
|
|
534
|
-
Session: "__session",
|
|
535
|
-
IdToken: "_tern",
|
|
536
|
-
CsrfToken: "_session_terncf",
|
|
537
|
-
SessionCookie: "_session_cookie",
|
|
538
|
-
SessionToken: "_session_token",
|
|
539
|
-
Refresh: "__refresh",
|
|
540
|
-
Handshake: "__ternsecure_handshake",
|
|
541
|
-
DevBrowser: "__ternsecure_db_jwt",
|
|
542
|
-
RedirectCount: "__ternsecure_redirect_count",
|
|
543
|
-
HandshakeNonce: "__ternsecure_handshake_nonce"
|
|
544
|
-
};
|
|
545
|
-
var Headers2 = {
|
|
546
|
-
Accept: "accept",
|
|
547
|
-
AuthMessage: "x-ternsecure-auth-message",
|
|
548
|
-
Authorization: "authorization",
|
|
549
|
-
AuthReason: "x-ternsecure-auth-reason",
|
|
550
|
-
AuthSignature: "x-ternsecure-auth-signature",
|
|
551
|
-
AuthStatus: "x-ternsecure-auth-status",
|
|
552
|
-
AuthToken: "x-ternsecure-auth-token",
|
|
553
|
-
CacheControl: "cache-control",
|
|
554
|
-
TernSecureRedirectTo: "x-ternsecure-redirect-to",
|
|
555
|
-
TernSecureRequestData: "x-ternsecure-request-data",
|
|
556
|
-
TernSecureUrl: "x-ternsecure-url",
|
|
557
|
-
CloudFrontForwardedProto: "cloudfront-forwarded-proto",
|
|
558
|
-
ContentType: "content-type",
|
|
559
|
-
ContentSecurityPolicy: "content-security-policy",
|
|
560
|
-
ContentSecurityPolicyReportOnly: "content-security-policy-report-only",
|
|
561
|
-
EnableDebug: "x-ternsecure-debug",
|
|
562
|
-
ForwardedHost: "x-forwarded-host",
|
|
563
|
-
ForwardedPort: "x-forwarded-port",
|
|
564
|
-
ForwardedProto: "x-forwarded-proto",
|
|
565
|
-
Host: "host",
|
|
566
|
-
Location: "location",
|
|
567
|
-
Nonce: "x-nonce",
|
|
568
|
-
Origin: "origin",
|
|
569
|
-
Referrer: "referer",
|
|
570
|
-
SecFetchDest: "sec-fetch-dest",
|
|
571
|
-
UserAgent: "user-agent",
|
|
572
|
-
ReportingEndpoints: "reporting-endpoints"
|
|
573
|
-
};
|
|
574
|
-
var ContentTypes = {
|
|
575
|
-
Json: "application/json"
|
|
576
|
-
};
|
|
577
|
-
var constants = {
|
|
578
|
-
Attributes,
|
|
579
|
-
Cookies,
|
|
580
|
-
Headers: Headers2,
|
|
581
|
-
ContentTypes
|
|
582
|
-
};
|
|
583
|
-
|
|
584
601
|
// src/tokens/ternUrl.ts
|
|
585
602
|
var TernUrl = class extends URL {
|
|
586
603
|
isCrossOrigin(other) {
|
|
@@ -697,6 +714,7 @@ function signedIn(session, headers = new Headers(), token) {
|
|
|
697
714
|
authenticateRequest,
|
|
698
715
|
clearSessionCookie,
|
|
699
716
|
createBackendInstance,
|
|
717
|
+
createCustomTokenClaims,
|
|
700
718
|
createSessionCookie,
|
|
701
719
|
createTenant,
|
|
702
720
|
createTenantUser,
|