@tern-secure/backend 1.2.0-canary.v20250926170202 → 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 +19 -28
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +23 -536
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/sessionTernSecure.d.ts +3 -0
- 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-ZMDLKXUP.mjs → chunk-4SGWLAJG.mjs} +3 -3
- package/dist/{chunk-ZMDLKXUP.mjs.map → chunk-4SGWLAJG.mjs.map} +1 -1
- 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/fireRestApi/emulator.d.ts +4 -0
- package/dist/fireRestApi/emulator.d.ts.map +1 -0
- package/dist/fireRestApi/endpointUrl.d.ts.map +1 -1
- package/dist/fireRestApi/endpoints/EmailApi.d.ts.map +1 -1
- package/dist/fireRestApi/endpoints/PasswordApi.d.ts.map +1 -1
- package/dist/fireRestApi/endpoints/SignInTokenApi.d.ts +4 -4
- package/dist/fireRestApi/endpoints/SignInTokenApi.d.ts.map +1 -1
- package/dist/fireRestApi/endpoints/SignUpApi.d.ts.map +1 -1
- package/dist/fireRestApi/endpoints/TokenApi.d.ts +7 -1
- package/dist/fireRestApi/endpoints/TokenApi.d.ts.map +1 -1
- package/dist/fireRestApi/request.d.ts +4 -7
- package/dist/fireRestApi/request.d.ts.map +1 -1
- package/dist/fireRestApi/resources/JSON.d.ts +6 -0
- package/dist/fireRestApi/resources/JSON.d.ts.map +1 -1
- package/dist/fireRestApi/resources/Token.d.ts +7 -1
- package/dist/fireRestApi/resources/Token.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +115 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -163
- package/dist/index.mjs.map +1 -1
- package/dist/tokens/keys.d.ts.map +1 -1
- package/dist/tokens/request.d.ts.map +1 -1
- package/dist/tokens/types.d.ts +1 -0
- 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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CACHE_CONTROL_REGEX,
|
|
3
|
+
DEFAULT_CACHE_DURATION,
|
|
4
|
+
GOOGLE_PUBLIC_KEYS_URL,
|
|
5
|
+
MAX_CACHE_LAST_UPDATED_AT_SECONDS
|
|
6
|
+
} from "./chunk-4SGWLAJG.mjs";
|
|
7
|
+
import {
|
|
8
|
+
TokenVerificationError,
|
|
9
|
+
TokenVerificationErrorReason,
|
|
10
|
+
ternDecodeJwt,
|
|
11
|
+
verifyJwt
|
|
12
|
+
} from "./chunk-WZYVAHZ3.mjs";
|
|
13
|
+
|
|
14
|
+
// src/tokens/keys.ts
|
|
15
|
+
var cache = {};
|
|
16
|
+
var lastUpdatedAt = 0;
|
|
17
|
+
var googleExpiresAt = 0;
|
|
18
|
+
function getFromCache(kid) {
|
|
19
|
+
return cache[kid];
|
|
20
|
+
}
|
|
21
|
+
function getCacheValues() {
|
|
22
|
+
return Object.values(cache);
|
|
23
|
+
}
|
|
24
|
+
function setInCache(kid, certificate, shouldExpire = true) {
|
|
25
|
+
cache[kid] = certificate;
|
|
26
|
+
lastUpdatedAt = shouldExpire ? Date.now() : -1;
|
|
27
|
+
}
|
|
28
|
+
async function fetchPublicKeys(keyUrl) {
|
|
29
|
+
const url = new URL(keyUrl);
|
|
30
|
+
const response = await fetch(url);
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
throw new TokenVerificationError({
|
|
33
|
+
message: `Error loading public keys from ${url.href} with code=${response.status} `,
|
|
34
|
+
reason: TokenVerificationErrorReason.TokenInvalid
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
const expiresAt = getExpiresAt(response);
|
|
39
|
+
return {
|
|
40
|
+
keys: data,
|
|
41
|
+
expiresAt
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function loadJWKFromRemote({
|
|
45
|
+
keyURL = GOOGLE_PUBLIC_KEYS_URL,
|
|
46
|
+
skipJwksCache,
|
|
47
|
+
kid
|
|
48
|
+
}) {
|
|
49
|
+
if (skipJwksCache || isCacheExpired() || !getFromCache(kid)) {
|
|
50
|
+
const { keys, expiresAt } = await fetchPublicKeys(keyURL);
|
|
51
|
+
if (!keys || Object.keys(keys).length === 0) {
|
|
52
|
+
throw new TokenVerificationError({
|
|
53
|
+
message: `The JWKS endpoint ${keyURL} returned no keys`,
|
|
54
|
+
reason: TokenVerificationErrorReason.RemoteJWKFailedToLoad
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
googleExpiresAt = expiresAt;
|
|
58
|
+
Object.entries(keys).forEach(([keyId, cert2]) => {
|
|
59
|
+
setInCache(keyId, cert2);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const cert = getFromCache(kid);
|
|
63
|
+
if (!cert) {
|
|
64
|
+
getCacheValues();
|
|
65
|
+
const availableKids = Object.keys(cache).sort().join(", ");
|
|
66
|
+
throw new TokenVerificationError({
|
|
67
|
+
message: `No public key found for kid "${kid}". Available kids: [${availableKids}]`,
|
|
68
|
+
reason: TokenVerificationErrorReason.TokenInvalid
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return cert;
|
|
72
|
+
}
|
|
73
|
+
function isCacheExpired() {
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
if (lastUpdatedAt === -1) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const cacheAge = now - lastUpdatedAt;
|
|
79
|
+
const maxCacheAge = MAX_CACHE_LAST_UPDATED_AT_SECONDS * 1e3;
|
|
80
|
+
const localCacheExpired = cacheAge >= maxCacheAge;
|
|
81
|
+
const googleCacheExpired = now >= googleExpiresAt;
|
|
82
|
+
const isExpired = localCacheExpired || googleCacheExpired;
|
|
83
|
+
if (isExpired) {
|
|
84
|
+
cache = {};
|
|
85
|
+
}
|
|
86
|
+
return isExpired;
|
|
87
|
+
}
|
|
88
|
+
function getExpiresAt(res) {
|
|
89
|
+
const cacheControlHeader = res.headers.get("cache-control");
|
|
90
|
+
if (!cacheControlHeader) {
|
|
91
|
+
return Date.now() + DEFAULT_CACHE_DURATION;
|
|
92
|
+
}
|
|
93
|
+
const maxAgeMatch = cacheControlHeader.match(CACHE_CONTROL_REGEX);
|
|
94
|
+
const maxAge = maxAgeMatch ? parseInt(maxAgeMatch[1], 10) : DEFAULT_CACHE_DURATION / 1e3;
|
|
95
|
+
return Date.now() + maxAge * 1e3;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/tokens/verify.ts
|
|
99
|
+
async function verifyToken(token, options) {
|
|
100
|
+
const { data: decodedResult, errors } = ternDecodeJwt(token);
|
|
101
|
+
if (errors) {
|
|
102
|
+
return { errors };
|
|
103
|
+
}
|
|
104
|
+
const { header } = decodedResult;
|
|
105
|
+
const { kid } = header;
|
|
106
|
+
if (!kid) {
|
|
107
|
+
return {
|
|
108
|
+
errors: [
|
|
109
|
+
new TokenVerificationError({
|
|
110
|
+
reason: TokenVerificationErrorReason.TokenInvalid,
|
|
111
|
+
message: 'JWT "kid" header is missing.'
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const key = options.jwtKey || await loadJWKFromRemote({ ...options, kid });
|
|
118
|
+
if (!key) {
|
|
119
|
+
return {
|
|
120
|
+
errors: [
|
|
121
|
+
new TokenVerificationError({
|
|
122
|
+
reason: TokenVerificationErrorReason.TokenInvalid,
|
|
123
|
+
message: `No public key found for kid "${kid}".`
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return await verifyJwt(token, { ...options, key });
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (error instanceof TokenVerificationError) {
|
|
131
|
+
return { errors: [error] };
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
errors: [error]
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
verifyToken
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=chunk-YKIA5EBF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tokens/keys.ts","../src/tokens/verify.ts"],"sourcesContent":["import { type RemoteJWKSetOptions } from 'jose';\n\nimport {\n CACHE_CONTROL_REGEX,\n DEFAULT_CACHE_DURATION,\n GOOGLE_PUBLIC_KEYS_URL,\n MAX_CACHE_LAST_UPDATED_AT_SECONDS\n} from '../constants';\nimport { TokenVerificationError, TokenVerificationErrorReason } from '../utils/errors';\n\nexport type PublicKeys = { [key: string]: string };\n\ninterface PublicKeysResponse {\n keys: PublicKeys;\n expiresAt: number;\n}\n\nexport type LoadJWKFromRemoteOptions = RemoteJWKSetOptions & {\n kid: string;\n keyURL?: string;\n skipJwksCache?: boolean;\n};\n\ntype CertificateCache = Record<string, string>;\n\nlet cache: CertificateCache = {};\nlet lastUpdatedAt = 0;\nlet googleExpiresAt = 0;\n\nfunction getFromCache(kid: string) {\n return cache[kid];\n}\n\nfunction getCacheValues() {\n return Object.values(cache);\n}\n\nfunction setInCache(kid: string, certificate: string, shouldExpire = true) {\n cache[kid] = certificate;\n lastUpdatedAt = shouldExpire ? Date.now() : -1;\n}\n\nasync function fetchPublicKeys(keyUrl: string): Promise<PublicKeysResponse> {\n const url = new URL(keyUrl);\n const response = await fetch(url);\n if (!response.ok) {\n throw new TokenVerificationError({\n message: `Error loading public keys from ${url.href} with code=${response.status} `,\n reason: TokenVerificationErrorReason.TokenInvalid,\n });\n }\n\n const data = await response.json();\n const expiresAt = getExpiresAt(response);\n\n return {\n keys: data,\n expiresAt,\n };\n}\n\nexport async function loadJWKFromRemote({\n keyURL = GOOGLE_PUBLIC_KEYS_URL,\n skipJwksCache,\n kid,\n}: LoadJWKFromRemoteOptions): Promise<string> {\n if (skipJwksCache || isCacheExpired() || !getFromCache(kid)) {\n const { keys, expiresAt } = await fetchPublicKeys(keyURL);\n\n if (!keys || Object.keys(keys).length === 0) {\n throw new TokenVerificationError({\n message: `The JWKS endpoint ${keyURL} returned no keys`,\n reason: TokenVerificationErrorReason.RemoteJWKFailedToLoad,\n });\n }\n googleExpiresAt = expiresAt;\n\n Object.entries(keys).forEach(([keyId, cert]) => {\n setInCache(keyId, cert);\n });\n }\n const cert = getFromCache(kid);\n if (!cert) {\n getCacheValues();\n const availableKids = Object.keys(cache).sort().join(', ');\n\n throw new TokenVerificationError({\n message: `No public key found for kid \"${kid}\". Available kids: [${availableKids}]`,\n reason: TokenVerificationErrorReason.TokenInvalid,\n });\n }\n return cert;\n}\n\nfunction isCacheExpired() {\n const now = Date.now();\n if (lastUpdatedAt === -1) {\n return false;\n }\n\n const cacheAge = now - lastUpdatedAt;\n const maxCacheAge = MAX_CACHE_LAST_UPDATED_AT_SECONDS * 1000;\n const localCacheExpired = cacheAge >= maxCacheAge;\n const googleCacheExpired = now >= googleExpiresAt;\n\n const isExpired = localCacheExpired || googleCacheExpired;\n\n if (isExpired) {\n cache = {};\n }\n\n return isExpired;\n}\n\nfunction getExpiresAt(res: Response) {\n const cacheControlHeader = res.headers.get('cache-control');\n if (!cacheControlHeader) {\n return Date.now() + DEFAULT_CACHE_DURATION;\n }\n const maxAgeMatch = cacheControlHeader.match(CACHE_CONTROL_REGEX);\n const maxAge = maxAgeMatch ? parseInt(maxAgeMatch[1], 10) : DEFAULT_CACHE_DURATION / 1000;\n\n return Date.now() + maxAge * 1000;\n}\n\nexport const getCacheStats = () => ({\n localExpiry: lastUpdatedAt + MAX_CACHE_LAST_UPDATED_AT_SECONDS * 1000,\n googleExpiry: googleExpiresAt,\n cacheCount: Object.keys(cache).length,\n});\n","import type { DecodedIdToken, TernSecureConfig } from '@tern-secure/types';\n\nimport type { JwtReturnType } from '../jwt/types';\nimport { ternDecodeJwt, verifyJwt, type VerifyJwtOptions } from '../jwt/verifyJwt';\nimport { TokenVerificationError, TokenVerificationErrorReason } from '../utils/errors';\nimport type { LoadJWKFromRemoteOptions } from './keys';\nimport { loadJWKFromRemote } from './keys';\n\nexport type VerifyTokenVOptions = Omit<VerifyJwtOptions, 'key'> & Omit<LoadJWKFromRemoteOptions, 'kid'> & {\n jwtKey?: string;\n};\n\nexport { TernSecureConfig };\n\nexport async function verifyToken(\n token: string,\n options: VerifyTokenVOptions,\n): Promise<JwtReturnType<DecodedIdToken, TokenVerificationError>> {\n const { data: decodedResult, errors } = ternDecodeJwt(token);\n\n if (errors) {\n return { errors };\n }\n\n const { header } = decodedResult;\n const { kid } = header;\n\n if (!kid) {\n return {\n errors: [\n new TokenVerificationError({\n reason: TokenVerificationErrorReason.TokenInvalid,\n message: 'JWT \"kid\" header is missing.',\n }),\n ],\n };\n }\n\n try {\n const key = options.jwtKey || (await loadJWKFromRemote({ ...options, kid }));\n\n if (!key) {\n return {\n errors: [\n new TokenVerificationError({\n reason: TokenVerificationErrorReason.TokenInvalid,\n message: `No public key found for kid \"${kid}\".`,\n }),\n ],\n };\n }\n return await verifyJwt(token, { ...options, key });\n } catch (error) {\n if (error instanceof TokenVerificationError) {\n return { errors: [error] };\n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,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AACF,UAAM,MAAM,QAAQ,UAAW,MAAM,kBAAkB,EAAE,GAAG,SAAS,IAAI,CAAC;AAE1E,QAAI,CAAC,KAAK;AACR,aAAO;AAAA,QACL,QAAQ;AAAA,UACN,IAAI,uBAAuB;AAAA,YACzB,QAAQ,6BAA6B;AAAA,YACrC,SAAS,gCAAgC,GAAG;AAAA,UAC9C,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AACA,WAAO,MAAM,UAAU,OAAO,EAAE,GAAG,SAAS,IAAI,CAAC;AAAA,EACnD,SAAS,OAAO;AACd,QAAI,iBAAiB,wBAAwB;AAC3C,aAAO,EAAE,QAAQ,CAAC,KAAK,EAAE;AAAA,IAC3B;AACA,WAAO;AAAA,MACL,QAAQ,CAAC,KAA+B;AAAA,IAC1C;AAAA,EACF;AACF;","names":["cert"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emulator.d.ts","sourceRoot":"","sources":["../../src/fireRestApi/emulator.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,oBAA0C,CAAC;AAEnF,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAGjD;AAED,wBAAgB,WAAW,IAAI,OAAO,CAErC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpointUrl.d.ts","sourceRoot":"","sources":["../../src/fireRestApi/endpointUrl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"endpointUrl.d.ts","sourceRoot":"","sources":["../../src/fireRestApi/endpointUrl.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,GAAI,QAAQ,MAAM,WAErD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,WAEhD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,WAE5C,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,WAUpD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,WAEnD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/EmailApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"EmailApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/EmailApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,KAAK,2BAA2B,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,qBAAa,QAAS,SAAQ,WAAW;IAC1B,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,2BAA2B;IAU3E,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;CAS7F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/PasswordApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"PasswordApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/PasswordApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,qBAAa,WAAY,SAAQ,WAAW;IAC7B,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,6BAA6B;IAU7E,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,0BAA0B;IAUrE,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB;CAS3E"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IdAndRefreshTokens } from '../resources/Token';
|
|
2
|
+
import { AbstractAPI } from './AbstractApi';
|
|
2
3
|
type CreateSignInTokenParams = {
|
|
3
|
-
|
|
4
|
-
password: string;
|
|
4
|
+
token: string;
|
|
5
5
|
returnSecureToken?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare class SignInTokenApi extends AbstractAPI {
|
|
8
|
-
createCustomToken(apiKey: string, params: CreateSignInTokenParams): Promise<
|
|
8
|
+
createCustomToken(apiKey: string, params: CreateSignInTokenParams): Promise<IdAndRefreshTokens>;
|
|
9
9
|
}
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=SignInTokenApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignInTokenApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/SignInTokenApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"SignInTokenApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/SignInTokenApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,qBAAa,cAAe,SAAQ,WAAW;IAChC,iBAAiB,CAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,kBAAkB,CAAC;CAsB/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignUpApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/SignUpApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"SignUpApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/SignUpApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAGF,qBAAa,SAAU,SAAQ,WAAW;IAC3B,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB;CAU/E"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IdAndRefreshTokens } from '../resources/Token';
|
|
2
|
+
import { AbstractAPI } from './AbstractApi';
|
|
2
3
|
type RefreshTokenParams = {
|
|
3
4
|
expired_token: string;
|
|
4
5
|
refresh_token: string;
|
|
@@ -8,8 +9,13 @@ type RefreshTokenParams = {
|
|
|
8
9
|
suffixed_cookies?: boolean;
|
|
9
10
|
format?: 'token' | 'cookie';
|
|
10
11
|
};
|
|
12
|
+
type IdAndRefreshTokensParams = {
|
|
13
|
+
token: string;
|
|
14
|
+
returnSecureToken?: boolean;
|
|
15
|
+
};
|
|
11
16
|
export declare class TokenApi extends AbstractAPI {
|
|
12
17
|
refreshToken(apiKey: string, params: RefreshTokenParams): Promise<import("../request").BackendApiResponse<unknown>>;
|
|
18
|
+
exchangeCustomForIdAndRefreshTokens(apiKey: string, params: IdAndRefreshTokensParams): Promise<IdAndRefreshTokens>;
|
|
13
19
|
}
|
|
14
20
|
export {};
|
|
15
21
|
//# sourceMappingURL=TokenApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/TokenApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"TokenApi.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/endpoints/TokenApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,KAAK,kBAAkB,GAAG;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7B,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,qBAAa,QAAS,SAAQ,WAAW;IAC1B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB;IAUvD,mCAAmC,CAC9C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC;CAyB/B"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { TernSecureAPIError, TernSecureApiErrorJSON } from "@tern-secure/types";
|
|
2
2
|
export type HTTPMethod = "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
|
|
3
|
+
export type FirebaseEndpoint = "refreshToken" | "signInWithPassword" | "signUp" | "signInWithCustomToken" | "passwordReset" | "sendOobCode";
|
|
3
4
|
export type BackendApiRequestOptions = {
|
|
5
|
+
endpoint: FirebaseEndpoint;
|
|
4
6
|
method?: HTTPMethod;
|
|
7
|
+
apiKey?: string;
|
|
5
8
|
queryParams?: Record<string, unknown>;
|
|
6
9
|
headerParams?: Record<string, string>;
|
|
7
10
|
bodyParams?: Record<string, unknown>;
|
|
8
11
|
formData?: FormData;
|
|
9
|
-
}
|
|
10
|
-
url: string;
|
|
11
|
-
path?: string;
|
|
12
|
-
} | {
|
|
13
|
-
url?: string;
|
|
14
|
-
path: string;
|
|
15
|
-
});
|
|
12
|
+
};
|
|
16
13
|
export type BackendApiResponse<T> = {
|
|
17
14
|
data: T;
|
|
18
15
|
errors: null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/fireRestApi/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/fireRestApi/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAY5B,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AACrE,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,oBAAoB,GACpB,QAAQ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-15,6 +15,7 @@ export declare const ObjectType: {
|
|
|
15
15
|
readonly SignUpAttempt: "sign_up_attempt";
|
|
16
16
|
readonly SmsMessage: "sms_message";
|
|
17
17
|
readonly User: "user";
|
|
18
|
+
readonly IdAndRefreshTokens: "id_and_refresh_tokens";
|
|
18
19
|
readonly Token: "token";
|
|
19
20
|
readonly TotalCount: "total_count";
|
|
20
21
|
readonly TestingToken: "testing_token";
|
|
@@ -41,4 +42,9 @@ export interface JwksKeyJSON {
|
|
|
41
42
|
n: string;
|
|
42
43
|
e: string;
|
|
43
44
|
}
|
|
45
|
+
export interface IdAndRefreshTokenJSON {
|
|
46
|
+
object: typeof ObjectType.IdAndRefreshTokens;
|
|
47
|
+
idToken: string;
|
|
48
|
+
refreshToken: string;
|
|
49
|
+
}
|
|
44
50
|
//# sourceMappingURL=JSON.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSON.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/resources/JSON.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JSON.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/resources/JSON.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;CAuBb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAGtE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,UAAU,CAAC,OAAO,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,OAAO,UAAU,CAAC,kBAAkB,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import type { TokenJSON } from './JSON';
|
|
1
|
+
import type { IdAndRefreshTokenJSON, TokenJSON } from './JSON';
|
|
2
2
|
export declare class Token {
|
|
3
3
|
readonly jwt: string;
|
|
4
4
|
constructor(jwt: string);
|
|
5
5
|
static fromJSON(data: TokenJSON): Token;
|
|
6
6
|
}
|
|
7
|
+
export declare class IdAndRefreshTokens {
|
|
8
|
+
readonly idToken: string;
|
|
9
|
+
readonly refreshToken: string;
|
|
10
|
+
constructor(idToken: string, refreshToken: string);
|
|
11
|
+
static fromJSON(data: IdAndRefreshTokenJSON): IdAndRefreshTokens;
|
|
12
|
+
}
|
|
7
13
|
//# sourceMappingURL=Token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Token.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/resources/Token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"Token.d.ts","sourceRoot":"","sources":["../../../src/fireRestApi/resources/Token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAC,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9D,qBAAa,KAAK;IACJ,QAAQ,CAAC,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM;IAEhC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK;CAGxC;AAED,qBAAa,kBAAkB;IAE3B,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM;gBADpB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM;IAG/B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,GAAG,kBAAkB;CAGjE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { AuthObject, RequestState, SignedInAuthObject, SignedOutAuthObject
|
|
|
6
6
|
export { signedIn, signedInAuthObject, signedOutAuthObject, AuthStatus } from './tokens/authstate';
|
|
7
7
|
export { createBackendInstanceClient } from "./instance/backendInstanceEdge";
|
|
8
8
|
export { createFireClient } from "./instance/backendFireInstance";
|
|
9
|
-
export type { BackendInstance, } from "./instance/backendInstanceEdge";
|
|
9
|
+
export type { BackendInstance, TernSecureBackendOptions } from "./instance/backendInstanceEdge";
|
|
10
10
|
export { enableDebugLogging, disableDebugLogging, setLogLevel, } from "./utils/enableDebugLogging";
|
|
11
11
|
export { LogLevel } from "./utils/logger";
|
|
12
12
|
export { RedisAdapter, PostgresAdapter, createAdapter, validateCheckRevokedOptions, } from "./adapters";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAErE,YAAY,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEjF,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAEjG,OAAO,EACL,2BAA2B,EAC5B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,YAAY,EACV,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAErE,YAAY,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEjF,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAEjG,OAAO,EACL,2BAA2B,EAC5B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,YAAY,EACV,eAAe,EACf,wBAAwB,EACzB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,GACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,aAAa,EACb,2BAA2B,GAC5B,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(index_exports);
|
|
41
41
|
|
|
42
42
|
// src/constants.ts
|
|
43
|
-
var
|
|
43
|
+
var GOOGLE_PUBLIC_KEYS_URL = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com";
|
|
44
44
|
var MAX_CACHE_LAST_UPDATED_AT_SECONDS = 5 * 60;
|
|
45
45
|
var DEFAULT_CACHE_DURATION = 3600 * 1e3;
|
|
46
46
|
var CACHE_CONTROL_REGEX = /max-age=(\d+)/;
|
|
@@ -284,14 +284,13 @@ var AbstractAPI = class {
|
|
|
284
284
|
};
|
|
285
285
|
|
|
286
286
|
// src/fireRestApi/endpoints/EmailApi.ts
|
|
287
|
-
var rootPath = "/customTokens";
|
|
288
287
|
var EmailApi = class extends AbstractAPI {
|
|
289
288
|
async verifyEmailVerification(apiKey, params) {
|
|
290
289
|
this.requireApiKey(apiKey);
|
|
291
290
|
const { ...restParams } = params;
|
|
292
291
|
return this.request({
|
|
292
|
+
endpoint: "sendOobCode",
|
|
293
293
|
method: "POST",
|
|
294
|
-
path: `${rootPath}`,
|
|
295
294
|
bodyParams: restParams
|
|
296
295
|
});
|
|
297
296
|
}
|
|
@@ -299,22 +298,21 @@ var EmailApi = class extends AbstractAPI {
|
|
|
299
298
|
this.requireApiKey(apiKey);
|
|
300
299
|
const { ...restParams } = params;
|
|
301
300
|
return this.request({
|
|
301
|
+
endpoint: "sendOobCode",
|
|
302
302
|
method: "POST",
|
|
303
|
-
path: `${rootPath}`,
|
|
304
303
|
bodyParams: restParams
|
|
305
304
|
});
|
|
306
305
|
}
|
|
307
306
|
};
|
|
308
307
|
|
|
309
308
|
// src/fireRestApi/endpoints/PasswordApi.ts
|
|
310
|
-
var rootPath2 = "/customTokens";
|
|
311
309
|
var PasswordApi = class extends AbstractAPI {
|
|
312
310
|
async verifyPasswordResetCode(apiKey, params) {
|
|
313
311
|
this.requireApiKey(apiKey);
|
|
314
312
|
const { ...restParams } = params;
|
|
315
313
|
return this.request({
|
|
314
|
+
endpoint: "passwordReset",
|
|
316
315
|
method: "POST",
|
|
317
|
-
path: `${rootPath2}`,
|
|
318
316
|
bodyParams: restParams
|
|
319
317
|
});
|
|
320
318
|
}
|
|
@@ -322,8 +320,8 @@ var PasswordApi = class extends AbstractAPI {
|
|
|
322
320
|
this.requireApiKey(apiKey);
|
|
323
321
|
const { ...restParams } = params;
|
|
324
322
|
return this.request({
|
|
323
|
+
endpoint: "passwordReset",
|
|
325
324
|
method: "POST",
|
|
326
|
-
path: `${rootPath2}`,
|
|
327
325
|
bodyParams: restParams
|
|
328
326
|
});
|
|
329
327
|
}
|
|
@@ -331,53 +329,81 @@ var PasswordApi = class extends AbstractAPI {
|
|
|
331
329
|
this.requireApiKey(apiKey);
|
|
332
330
|
const { ...restParams } = params;
|
|
333
331
|
return this.request({
|
|
332
|
+
endpoint: "passwordReset",
|
|
334
333
|
method: "POST",
|
|
335
|
-
path: `${rootPath2}`,
|
|
336
334
|
bodyParams: restParams
|
|
337
335
|
});
|
|
338
336
|
}
|
|
339
337
|
};
|
|
340
338
|
|
|
341
339
|
// src/fireRestApi/endpoints/SignInTokenApi.ts
|
|
342
|
-
var rootPath3 = "/customTokens";
|
|
343
340
|
var SignInTokenApi = class extends AbstractAPI {
|
|
344
341
|
async createCustomToken(apiKey, params) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
342
|
+
try {
|
|
343
|
+
this.requireApiKey(apiKey);
|
|
344
|
+
const { ...restParams } = params;
|
|
345
|
+
const response = await this.request({
|
|
346
|
+
endpoint: "signInWithCustomToken",
|
|
347
|
+
method: "POST",
|
|
348
|
+
bodyParams: restParams
|
|
349
|
+
});
|
|
350
|
+
if (response.errors) {
|
|
351
|
+
const errorMessage = response.errors[0]?.message || "Failed to create custom token";
|
|
352
|
+
throw new Error(errorMessage);
|
|
353
|
+
}
|
|
354
|
+
return response.data;
|
|
355
|
+
} catch (error) {
|
|
356
|
+
const contextualMessage = `Failed to create custom token: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
357
|
+
throw new Error(contextualMessage);
|
|
358
|
+
}
|
|
352
359
|
}
|
|
353
360
|
};
|
|
354
361
|
|
|
355
362
|
// src/fireRestApi/endpoints/SignUpApi.ts
|
|
356
|
-
var rootPath4 = "/customTokens";
|
|
357
363
|
var SignUpApi = class extends AbstractAPI {
|
|
358
364
|
async createCustomToken(apiKey, params) {
|
|
359
365
|
this.requireApiKey(apiKey);
|
|
360
366
|
const { ...restParams } = params;
|
|
361
367
|
return this.request({
|
|
368
|
+
endpoint: "signUp",
|
|
362
369
|
method: "POST",
|
|
363
|
-
path: `${rootPath4}`,
|
|
364
370
|
bodyParams: restParams
|
|
365
371
|
});
|
|
366
372
|
}
|
|
367
373
|
};
|
|
368
374
|
|
|
369
375
|
// src/fireRestApi/endpoints/TokenApi.ts
|
|
370
|
-
var rootPath5 = "/sessions";
|
|
371
376
|
var TokenApi = class extends AbstractAPI {
|
|
372
377
|
async refreshToken(apiKey, params) {
|
|
373
378
|
this.requireApiKey(apiKey);
|
|
374
379
|
const { ...restParams } = params;
|
|
375
380
|
return this.request({
|
|
381
|
+
endpoint: "refreshToken",
|
|
376
382
|
method: "POST",
|
|
377
|
-
path: `${rootPath5}/refresh`,
|
|
378
383
|
bodyParams: restParams
|
|
379
384
|
});
|
|
380
385
|
}
|
|
386
|
+
async exchangeCustomForIdAndRefreshTokens(apiKey, params) {
|
|
387
|
+
try {
|
|
388
|
+
this.requireApiKey(apiKey);
|
|
389
|
+
const { ...restParams } = params;
|
|
390
|
+
const response = await this.request({
|
|
391
|
+
endpoint: "signInWithCustomToken",
|
|
392
|
+
method: "POST",
|
|
393
|
+
apiKey,
|
|
394
|
+
bodyParams: restParams
|
|
395
|
+
});
|
|
396
|
+
if (response.errors) {
|
|
397
|
+
const errorMessage = response.errors[0]?.message || "Failed to create custom token";
|
|
398
|
+
console.error("Error response from exchangeCustomForIdAndRefreshTokens:", response.errors);
|
|
399
|
+
throw new Error(errorMessage);
|
|
400
|
+
}
|
|
401
|
+
return response.data;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
const contextualMessage = `Failed to create custom token: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
404
|
+
throw new Error(contextualMessage);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
381
407
|
};
|
|
382
408
|
|
|
383
409
|
// src/runtime.ts
|
|
@@ -396,20 +422,69 @@ var runtime = {
|
|
|
396
422
|
Response: globalThis.Response
|
|
397
423
|
};
|
|
398
424
|
|
|
399
|
-
// src/
|
|
400
|
-
var
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return
|
|
425
|
+
// src/fireRestApi/emulator.ts
|
|
426
|
+
var FIREBASE_AUTH_EMULATOR_HOST = process.env.FIREBASE_AUTH_EMULATOR_HOST;
|
|
427
|
+
function emulatorHost() {
|
|
428
|
+
if (typeof process === "undefined") return void 0;
|
|
429
|
+
return FIREBASE_AUTH_EMULATOR_HOST;
|
|
430
|
+
}
|
|
431
|
+
function useEmulator() {
|
|
432
|
+
return !!emulatorHost();
|
|
404
433
|
}
|
|
405
434
|
|
|
435
|
+
// src/fireRestApi/endpointUrl.ts
|
|
436
|
+
var getRefreshTokenEndpoint = (apiKey) => {
|
|
437
|
+
return `https://securetoken.googleapis.com/v1/token?key=${apiKey}`;
|
|
438
|
+
};
|
|
439
|
+
var signInWithPassword = (apiKey) => {
|
|
440
|
+
return `https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=${apiKey}`;
|
|
441
|
+
};
|
|
442
|
+
var signUpEndpoint = (apiKey) => {
|
|
443
|
+
return `https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=${apiKey}`;
|
|
444
|
+
};
|
|
445
|
+
var getCustomTokenEndpoint = (apiKey) => {
|
|
446
|
+
if (useEmulator() && FIREBASE_AUTH_EMULATOR_HOST) {
|
|
447
|
+
let protocol = "http://";
|
|
448
|
+
if (FIREBASE_AUTH_EMULATOR_HOST.startsWith("http://")) {
|
|
449
|
+
protocol = "";
|
|
450
|
+
}
|
|
451
|
+
return `${protocol}${FIREBASE_AUTH_EMULATOR_HOST}/identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${apiKey}`;
|
|
452
|
+
}
|
|
453
|
+
return `https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${apiKey}`;
|
|
454
|
+
};
|
|
455
|
+
var passwordResetEndpoint = (apiKey) => {
|
|
456
|
+
return `https://identitytoolkit.googleapis.com/v1/accounts:resetPassword?key=${apiKey}`;
|
|
457
|
+
};
|
|
458
|
+
|
|
406
459
|
// src/fireRestApi/request.ts
|
|
460
|
+
var FIREBASE_ENDPOINT_MAP = {
|
|
461
|
+
refreshToken: getRefreshTokenEndpoint,
|
|
462
|
+
signInWithPassword,
|
|
463
|
+
signUp: signUpEndpoint,
|
|
464
|
+
signInWithCustomToken: getCustomTokenEndpoint,
|
|
465
|
+
passwordReset: passwordResetEndpoint,
|
|
466
|
+
sendOobCode: signInWithPassword
|
|
467
|
+
};
|
|
407
468
|
function createRequest(options) {
|
|
408
469
|
const requestFn = async (requestOptions) => {
|
|
409
|
-
const { apiKey,
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
470
|
+
const { endpoint, method, apiKey, queryParams, headerParams, bodyParams, formData } = requestOptions;
|
|
471
|
+
if (!apiKey) {
|
|
472
|
+
return {
|
|
473
|
+
data: null,
|
|
474
|
+
errors: [
|
|
475
|
+
{
|
|
476
|
+
code: "missing_api_key",
|
|
477
|
+
message: "Firebase API key is required"
|
|
478
|
+
}
|
|
479
|
+
]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
const endpointUrl = FIREBASE_ENDPOINT_MAP[endpoint](apiKey);
|
|
483
|
+
const finalUrl = new URL(endpointUrl);
|
|
484
|
+
console.log("endpoint url:", endpointUrl);
|
|
485
|
+
console.log("Final URL href:", finalUrl.href);
|
|
486
|
+
console.log("Final URL:", finalUrl);
|
|
487
|
+
console.log("Method:", method);
|
|
413
488
|
if (queryParams) {
|
|
414
489
|
Object.entries(queryParams).forEach(([key, value]) => {
|
|
415
490
|
if (value) {
|
|
@@ -500,6 +575,9 @@ function createFireApi(options) {
|
|
|
500
575
|
};
|
|
501
576
|
}
|
|
502
577
|
|
|
578
|
+
// src/tokens/request.ts
|
|
579
|
+
var import_cookie2 = require("@tern-secure/shared/cookie");
|
|
580
|
+
|
|
503
581
|
// src/utils/errors.ts
|
|
504
582
|
var TokenVerificationErrorReason = {
|
|
505
583
|
TokenExpired: "token-expired",
|
|
@@ -537,6 +615,7 @@ var TokenVerificationError = class _TokenVerificationError extends Error {
|
|
|
537
615
|
|
|
538
616
|
// src/utils/options.ts
|
|
539
617
|
var defaultOptions = {
|
|
618
|
+
apiKey: void 0,
|
|
540
619
|
apiUrl: void 0,
|
|
541
620
|
apiVersion: void 0
|
|
542
621
|
};
|
|
@@ -842,7 +921,7 @@ async function fetchPublicKeys(keyUrl) {
|
|
|
842
921
|
};
|
|
843
922
|
}
|
|
844
923
|
async function loadJWKFromRemote({
|
|
845
|
-
keyURL =
|
|
924
|
+
keyURL = GOOGLE_PUBLIC_KEYS_URL,
|
|
846
925
|
skipJwksCache,
|
|
847
926
|
kid
|
|
848
927
|
}) {
|
|
@@ -950,6 +1029,11 @@ function extractTokenFromCookie(request) {
|
|
|
950
1029
|
if (!cookieHeader) {
|
|
951
1030
|
return null;
|
|
952
1031
|
}
|
|
1032
|
+
const cookiePrefix = (0, import_cookie2.getCookiePrefix)();
|
|
1033
|
+
const idTokenCookieName = (0, import_cookie2.getCookieName)(
|
|
1034
|
+
constants.Cookies.IdToken,
|
|
1035
|
+
cookiePrefix
|
|
1036
|
+
);
|
|
953
1037
|
const cookies = cookieHeader.split(";").reduce(
|
|
954
1038
|
(acc, cookie) => {
|
|
955
1039
|
const [name, value] = cookie.trim().split("=");
|
|
@@ -958,7 +1042,7 @@ function extractTokenFromCookie(request) {
|
|
|
958
1042
|
},
|
|
959
1043
|
{}
|
|
960
1044
|
);
|
|
961
|
-
return
|
|
1045
|
+
return idTokenCookieName || null;
|
|
962
1046
|
}
|
|
963
1047
|
function hasAuthorizationHeader(request) {
|
|
964
1048
|
return request.headers.has("Authorization");
|