firebase-admin-edge 1.0.21 → 1.0.23
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 +58 -20
- package/dist/auth/auth-endpoint-errors.test.d.ts +2 -0
- package/dist/auth/auth-endpoint-errors.test.d.ts.map +1 -0
- package/dist/auth/auth-endpoint-errors.test.js +403 -0
- package/dist/auth/auth-endpoint-errors.test.js.map +1 -0
- package/dist/auth/cache-types.d.ts +7 -0
- package/dist/auth/cache-types.d.ts.map +1 -0
- package/dist/auth/cache-types.js +2 -0
- package/dist/auth/cache-types.js.map +1 -0
- package/dist/auth/cookie-types.d.ts +4 -0
- package/dist/auth/cookie-types.d.ts.map +1 -1
- package/dist/auth/errors.test.d.ts +2 -0
- package/dist/auth/errors.test.d.ts.map +1 -0
- package/dist/auth/errors.test.js +123 -0
- package/dist/auth/errors.test.js.map +1 -0
- package/dist/auth/firebase-admin-auth.d.ts +75 -10
- package/dist/auth/firebase-admin-auth.d.ts.map +1 -1
- package/dist/auth/firebase-admin-auth.js +111 -28
- package/dist/auth/firebase-admin-auth.js.map +1 -1
- package/dist/auth/firebase-admin-auth.test.js +144 -35
- package/dist/auth/firebase-admin-auth.test.js.map +1 -1
- package/dist/auth/firebase-auth-endpoints.d.ts +50 -11
- package/dist/auth/firebase-auth-endpoints.d.ts.map +1 -1
- package/dist/auth/firebase-auth-endpoints.js +101 -4
- package/dist/auth/firebase-auth-endpoints.js.map +1 -1
- package/dist/auth/firebase-auth-endpoints.test.js +331 -8
- package/dist/auth/firebase-auth-endpoints.test.js.map +1 -1
- package/dist/auth/firebase-auth.d.ts +43 -2
- package/dist/auth/firebase-auth.d.ts.map +1 -1
- package/dist/auth/firebase-auth.js +85 -7
- package/dist/auth/firebase-auth.js.map +1 -1
- package/dist/auth/firebase-auth.test.js +57 -4
- package/dist/auth/firebase-auth.test.js.map +1 -1
- package/dist/auth/firebase-jwt.d.ts.map +1 -1
- package/dist/auth/firebase-jwt.js +1 -0
- package/dist/auth/firebase-jwt.js.map +1 -1
- package/dist/auth/firebase-types.d.ts +17 -0
- package/dist/auth/firebase-types.d.ts.map +1 -1
- package/dist/auth/google-oauth.d.ts +5 -10
- package/dist/auth/google-oauth.d.ts.map +1 -1
- package/dist/auth/google-oauth.js +12 -1
- package/dist/auth/google-oauth.js.map +1 -1
- package/dist/auth/oauth.d.ts +2 -2
- package/dist/auth/oauth.d.ts.map +1 -1
- package/dist/auth/oauth.js +43 -23
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/oauth.test.js +44 -172
- package/dist/auth/oauth.test.js.map +1 -1
- package/dist/firebase-edge-server.d.ts +28 -14
- package/dist/firebase-edge-server.d.ts.map +1 -1
- package/dist/firebase-edge-server.js +61 -35
- package/dist/firebase-edge-server.js.map +1 -1
- package/dist/firebase-edge-server.test.js +7 -7
- package/dist/firebase-edge-server.test.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/token-cache.d.ts +9 -0
- package/dist/utils/token-cache.d.ts.map +1 -0
- package/dist/utils/token-cache.js +27 -0
- package/dist/utils/token-cache.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { ensureError, FirebaseEdgeError, FirebaseAdminAuthErrorInfo } from './errors.js';
|
|
3
|
+
describe('Error Utilities', () => {
|
|
4
|
+
describe('ensureError', () => {
|
|
5
|
+
it('returns the error if already an Error instance', () => {
|
|
6
|
+
const error = new Error('Test error');
|
|
7
|
+
const result = ensureError(error);
|
|
8
|
+
expect(result).toBe(error);
|
|
9
|
+
expect(result.message).toBe('Test error');
|
|
10
|
+
});
|
|
11
|
+
it('returns the FirebaseEdgeError if already a FirebaseEdgeError', () => {
|
|
12
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_NOT_FOUND);
|
|
13
|
+
const result = ensureError(error);
|
|
14
|
+
expect(result).toBe(error);
|
|
15
|
+
expect(result).toBeInstanceOf(FirebaseEdgeError);
|
|
16
|
+
});
|
|
17
|
+
it('wraps non-Error values in an Error with stringified content', () => {
|
|
18
|
+
const value = { code: 400, message: 'Bad Request' };
|
|
19
|
+
const result = ensureError(value);
|
|
20
|
+
expect(result).toBeInstanceOf(Error);
|
|
21
|
+
expect(result.message).toContain('This value was thrown as is');
|
|
22
|
+
expect(result.message).toContain('400');
|
|
23
|
+
expect(result.message).toContain('Bad Request');
|
|
24
|
+
});
|
|
25
|
+
it('handles string values', () => {
|
|
26
|
+
const value = 'Something went wrong';
|
|
27
|
+
const result = ensureError(value);
|
|
28
|
+
expect(result).toBeInstanceOf(Error);
|
|
29
|
+
expect(result.message).toContain('This value was thrown as is');
|
|
30
|
+
expect(result.message).toContain('Something went wrong');
|
|
31
|
+
});
|
|
32
|
+
it('handles number values', () => {
|
|
33
|
+
const value = 404;
|
|
34
|
+
const result = ensureError(value);
|
|
35
|
+
expect(result).toBeInstanceOf(Error);
|
|
36
|
+
expect(result.message).toContain('This value was thrown as is');
|
|
37
|
+
expect(result.message).toContain('404');
|
|
38
|
+
});
|
|
39
|
+
it('handles null values', () => {
|
|
40
|
+
const result = ensureError(null);
|
|
41
|
+
expect(result).toBeInstanceOf(Error);
|
|
42
|
+
expect(result.message).toContain('This value was thrown as is');
|
|
43
|
+
expect(result.message).toContain('null');
|
|
44
|
+
});
|
|
45
|
+
it('handles undefined values', () => {
|
|
46
|
+
const result = ensureError(undefined);
|
|
47
|
+
expect(result).toBeInstanceOf(Error);
|
|
48
|
+
expect(result.message).toContain('This value was thrown as is');
|
|
49
|
+
});
|
|
50
|
+
it('handles circular references gracefully', () => {
|
|
51
|
+
const circular = { name: 'circular' };
|
|
52
|
+
circular.self = circular;
|
|
53
|
+
const result = ensureError(circular);
|
|
54
|
+
expect(result).toBeInstanceOf(Error);
|
|
55
|
+
expect(result.message).toContain('Unable to stringify the thrown value');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('FirebaseEdgeError', () => {
|
|
59
|
+
it('creates error with message and code', () => {
|
|
60
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_NOT_FOUND);
|
|
61
|
+
expect(error).toBeInstanceOf(Error);
|
|
62
|
+
expect(error).toBeInstanceOf(FirebaseEdgeError);
|
|
63
|
+
expect(error.name).toBe('FirebaseEdgeError');
|
|
64
|
+
expect(error.message).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_NOT_FOUND.message);
|
|
65
|
+
expect(error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_NOT_FOUND.code);
|
|
66
|
+
});
|
|
67
|
+
it('includes cause when provided', () => {
|
|
68
|
+
const cause = new Error('Original error');
|
|
69
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_ID_TOKEN_VERIFY_FAILED, { cause });
|
|
70
|
+
expect(error.cause).toBe(cause);
|
|
71
|
+
expect(error.message).toBe(FirebaseAdminAuthErrorInfo.ADMIN_ID_TOKEN_VERIFY_FAILED.message);
|
|
72
|
+
});
|
|
73
|
+
it('includes context when provided', () => {
|
|
74
|
+
const context = { uid: 'user-123', provider: 'google.com' };
|
|
75
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_LOOKUP_FAILED, { context });
|
|
76
|
+
expect(error.context).toEqual(context);
|
|
77
|
+
expect(error.message).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_LOOKUP_FAILED.message);
|
|
78
|
+
});
|
|
79
|
+
it('includes both cause and context', () => {
|
|
80
|
+
const cause = new Error('Network failure');
|
|
81
|
+
const context = { url: 'https://api.example.com', timeout: 5000 };
|
|
82
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_API_NETWORK_ERROR, { cause, context });
|
|
83
|
+
expect(error.cause).toBe(cause);
|
|
84
|
+
expect(error.context).toEqual(context);
|
|
85
|
+
expect(error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_API_NETWORK_ERROR.code);
|
|
86
|
+
});
|
|
87
|
+
it('works without options', () => {
|
|
88
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_UNKNOWN_ERROR);
|
|
89
|
+
expect(error.cause).toBeUndefined();
|
|
90
|
+
expect(error.context).toBeUndefined();
|
|
91
|
+
expect(error.message).toBe(FirebaseAdminAuthErrorInfo.ADMIN_UNKNOWN_ERROR.message);
|
|
92
|
+
});
|
|
93
|
+
it('maintains prototype chain', () => {
|
|
94
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_INTERNAL_ERROR);
|
|
95
|
+
expect(error instanceof FirebaseEdgeError).toBe(true);
|
|
96
|
+
expect(error instanceof Error).toBe(true);
|
|
97
|
+
expect(Object.getPrototypeOf(error)).toBe(FirebaseEdgeError.prototype);
|
|
98
|
+
});
|
|
99
|
+
it('is catchable and type-checkable', () => {
|
|
100
|
+
try {
|
|
101
|
+
throw new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_TOKEN_REVOCATION_CHECK_FAILED, { context: { reason: 'test' } });
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
expect(err).toBeInstanceOf(FirebaseEdgeError);
|
|
105
|
+
if (err instanceof FirebaseEdgeError) {
|
|
106
|
+
expect(err.code).toBe(FirebaseAdminAuthErrorInfo
|
|
107
|
+
.ADMIN_TOKEN_REVOCATION_CHECK_FAILED.code);
|
|
108
|
+
expect(err.context).toEqual({ reason: 'test' });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
it('supports nested JSON context', () => {
|
|
113
|
+
const context = {
|
|
114
|
+
user: { id: '123', email: 'test@example.com' },
|
|
115
|
+
metadata: { timestamp: 1234567890, source: 'api' },
|
|
116
|
+
tags: ['urgent', 'security']
|
|
117
|
+
};
|
|
118
|
+
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_OPERATION_FAILED, { context });
|
|
119
|
+
expect(error.context).toEqual(context);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=errors.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../../src/auth/errors.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,0BAA0B,EAC7B,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACtD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YAElC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;YACpE,MAAM,KAAK,GAAG,IAAI,iBAAiB,CAC/B,0BAA0B,CAAC,oBAAoB,CAClD,CAAC;YACF,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YAElC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6DAA6D,EAAE,GA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,CACd,CAAC;YAEF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
import type { ServiceAccount } from './firebase-types.js';
|
|
2
2
|
import { FirebaseEdgeError } from './errors.js';
|
|
3
|
+
import type { CacheConfig } from './cache-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Firebase Admin Authentication handler for edge environments.
|
|
6
|
+
* Provides server-side authentication operations using service account credentials.
|
|
7
|
+
*/
|
|
3
8
|
export declare class FirebaseAdminAuth {
|
|
4
9
|
private serviceAccountKey;
|
|
5
10
|
private tenantId?;
|
|
6
11
|
private fetch?;
|
|
7
|
-
|
|
12
|
+
private cache?;
|
|
13
|
+
private cacheName?;
|
|
14
|
+
private _cacheName;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Firebase Admin Auth instance.
|
|
17
|
+
*
|
|
18
|
+
* @param serviceAccountKey Firebase service account credentials
|
|
19
|
+
* @param tenantId Optional tenant ID for multi-tenancy
|
|
20
|
+
* @param fetch Optional custom fetch implementation
|
|
21
|
+
* @param cache Optional cache implementation for token caching
|
|
22
|
+
* @param cacheName Optional cache key name (defaults to '__cache')
|
|
23
|
+
*/
|
|
24
|
+
constructor(serviceAccountKey: ServiceAccount, tenantId?: string | undefined, fetch?: typeof globalThis.fetch | undefined, cache?: CacheConfig | undefined, cacheName?: string | undefined);
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves a cached service account token or fetches a new one.
|
|
27
|
+
* Tokens are cached for 1 hour.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise with token data and error
|
|
30
|
+
*/
|
|
31
|
+
private getCachedToken;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves user account information by UID.
|
|
34
|
+
*
|
|
35
|
+
* @param uid User ID to look up
|
|
36
|
+
* @returns Promise with object containing user data or null, and error if any
|
|
37
|
+
*/
|
|
8
38
|
getUser(uid: string): Promise<{
|
|
9
39
|
data: null;
|
|
10
40
|
error: FirebaseEdgeError;
|
|
@@ -12,29 +42,64 @@ export declare class FirebaseAdminAuth {
|
|
|
12
42
|
data: import("./firebase-types.js").UserRecord | null | undefined;
|
|
13
43
|
error: null;
|
|
14
44
|
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves user account information by email address.
|
|
47
|
+
*
|
|
48
|
+
* @param email Email address to look up
|
|
49
|
+
* @returns Promise with object containing user data or null, and error if any
|
|
50
|
+
*/
|
|
51
|
+
getUserByEmail(email: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Verifies a Firebase ID token and returns the decoded payload.
|
|
54
|
+
* Optionally checks if the token has been revoked.
|
|
55
|
+
*
|
|
56
|
+
* @param idToken Firebase ID token to verify
|
|
57
|
+
* @param checkRevoked Whether to check if token has been revoked (defaults to false)
|
|
58
|
+
* @returns Promise with object containing decoded token payload or null, and error if any
|
|
59
|
+
*/
|
|
15
60
|
verifyIdToken(idToken: string, checkRevoked?: boolean): Promise<{
|
|
61
|
+
data: null;
|
|
62
|
+
error: FirebaseEdgeError;
|
|
63
|
+
} | {
|
|
16
64
|
data: import("./firebase-types.js").FirebaseIdTokenPayload;
|
|
17
65
|
error: null;
|
|
18
|
-
} | {
|
|
19
|
-
data: null;
|
|
20
|
-
error: Error;
|
|
21
66
|
}>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Creates a session cookie from a Firebase ID token.
|
|
69
|
+
*
|
|
70
|
+
* @param idToken Firebase ID token to convert to session cookie
|
|
71
|
+
* @param expiresIn_ms Session cookie expiration time in milliseconds
|
|
72
|
+
* @returns Promise with object containing session cookie string or null, and error if any
|
|
73
|
+
*/
|
|
74
|
+
createSessionCookie(idToken: string, expiresIn_ms: number): Promise<{
|
|
25
75
|
data: null;
|
|
26
76
|
error: FirebaseEdgeError;
|
|
27
77
|
} | {
|
|
28
78
|
data: string | null;
|
|
29
79
|
error: null;
|
|
30
80
|
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Verifies a Firebase session cookie and returns the decoded payload.
|
|
83
|
+
* Optionally checks if the token has been revoked.
|
|
84
|
+
*
|
|
85
|
+
* @param sessionCookie Session cookie to verify
|
|
86
|
+
* @param checkRevoked Whether to check if token has been revoked (defaults to false)
|
|
87
|
+
* @returns Promise with object containing decoded session payload or null, and error if any
|
|
88
|
+
*/
|
|
31
89
|
verifySessionCookie(sessionCookie: string, checkRevoked?: boolean): Promise<{
|
|
90
|
+
data: null;
|
|
91
|
+
error: FirebaseEdgeError;
|
|
92
|
+
} | {
|
|
32
93
|
data: import("./firebase-types.js").FirebaseIdTokenPayload;
|
|
33
94
|
error: null;
|
|
34
|
-
} | {
|
|
35
|
-
data: null;
|
|
36
|
-
error: Error;
|
|
37
95
|
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a custom Firebase authentication token for a given user.
|
|
98
|
+
*
|
|
99
|
+
* @param uid User ID to create token for
|
|
100
|
+
* @param developerClaims Optional custom claims to include in the token
|
|
101
|
+
* @returns Promise with object containing custom token string or null, and error if any
|
|
102
|
+
*/
|
|
38
103
|
createCustomToken(uid: string, developerClaims?: object): Promise<{
|
|
39
104
|
data: null;
|
|
40
105
|
error: FirebaseEdgeError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase-admin-auth.d.ts","sourceRoot":"","sources":["../../src/auth/firebase-admin-auth.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"firebase-admin-auth.d.ts","sourceRoot":"","sources":["../../src/auth/firebase-admin-auth.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAuB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE/E,OAAO,EACH,iBAAiB,EAGpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,qBAAa,iBAAiB;IAatB,OAAO,CAAC,iBAAiB;IACzB,OAAO,CAAC,QAAQ,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC;IACd,OAAO,CAAC,KAAK,CAAC;IACd,OAAO,CAAC,SAAS,CAAC;IAhBtB,OAAO,CAAC,UAAU,CAAa;IAE/B;;;;;;;;OAQG;gBAES,iBAAiB,EAAE,cAAc,EACjC,QAAQ,CAAC,EAAE,MAAM,YAAA,EACjB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,YAAA,EAC/B,KAAK,CAAC,EAAE,WAAW,YAAA,EACnB,SAAS,CAAC,EAAE,MAAM,YAAA;IAK9B;;;;;OAKG;YACW,cAAc;IAoC5B;;;;;OAKG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM;;;;;;;IA+BzB;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM;IAElC;;;;;;;OAOG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,OAAe;;;;;;;IA6GlE;;;;;;OAMG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;;;;IAuC/D;;;;;;;OAOG;IACG,mBAAmB,CACrB,aAAa,EAAE,MAAM,EACrB,YAAY,GAAE,OAAe;;;;;;;IAgFjC;;;;;;OAMG;IACG,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,GAAE,MAAW;;;;;;;CAmCpE"}
|
|
@@ -1,32 +1,80 @@
|
|
|
1
|
-
import { createSessionCookie,
|
|
1
|
+
import { createSessionCookie, getAccountInfo } from './firebase-auth-endpoints.js';
|
|
2
2
|
import { signJWTCustomToken, verifyJWT, verifySessionJWT } from './firebase-jwt.js';
|
|
3
3
|
import { getToken } from './google-oauth.js';
|
|
4
4
|
import { FirebaseEdgeError, FirebaseAdminAuthErrorInfo, ensureError } from './errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Firebase Admin Authentication handler for edge environments.
|
|
7
|
+
* Provides server-side authentication operations using service account credentials.
|
|
8
|
+
*/
|
|
5
9
|
export class FirebaseAdminAuth {
|
|
6
10
|
serviceAccountKey;
|
|
7
11
|
tenantId;
|
|
8
12
|
fetch;
|
|
9
|
-
|
|
13
|
+
cache;
|
|
14
|
+
cacheName;
|
|
15
|
+
_cacheName = '__cache';
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new Firebase Admin Auth instance.
|
|
18
|
+
*
|
|
19
|
+
* @param serviceAccountKey Firebase service account credentials
|
|
20
|
+
* @param tenantId Optional tenant ID for multi-tenancy
|
|
21
|
+
* @param fetch Optional custom fetch implementation
|
|
22
|
+
* @param cache Optional cache implementation for token caching
|
|
23
|
+
* @param cacheName Optional cache key name (defaults to '__cache')
|
|
24
|
+
*/
|
|
25
|
+
constructor(serviceAccountKey, tenantId, fetch, cache, cacheName) {
|
|
10
26
|
this.serviceAccountKey = serviceAccountKey;
|
|
11
27
|
this.tenantId = tenantId;
|
|
12
28
|
this.fetch = fetch;
|
|
29
|
+
this.cache = cache;
|
|
30
|
+
this.cacheName = cacheName;
|
|
31
|
+
this._cacheName = this.cacheName || this._cacheName;
|
|
13
32
|
}
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves a cached service account token or fetches a new one.
|
|
35
|
+
* Tokens are cached for 1 hour.
|
|
36
|
+
*
|
|
37
|
+
* @returns Promise with token data and error
|
|
38
|
+
*/
|
|
39
|
+
async getCachedToken() {
|
|
40
|
+
const cachedToken = await this.cache?.getCache(this._cacheName);
|
|
41
|
+
if (cachedToken) {
|
|
42
|
+
return {
|
|
43
|
+
data: cachedToken,
|
|
44
|
+
error: null
|
|
45
|
+
};
|
|
46
|
+
}
|
|
16
47
|
const { data: token, error: getTokenError } = await getToken(this.serviceAccountKey, this.fetch);
|
|
48
|
+
if (token && this.cache) {
|
|
49
|
+
// Google tokens are valid for 1 hour
|
|
50
|
+
this.cache?.setCache('token', token, 3600);
|
|
51
|
+
}
|
|
17
52
|
if (getTokenError) {
|
|
18
53
|
return {
|
|
19
54
|
data: null,
|
|
20
|
-
error:
|
|
55
|
+
error: getTokenError
|
|
21
56
|
};
|
|
22
57
|
}
|
|
23
|
-
|
|
58
|
+
return {
|
|
59
|
+
data: token,
|
|
60
|
+
error: null
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves user account information by UID.
|
|
65
|
+
*
|
|
66
|
+
* @param uid User ID to look up
|
|
67
|
+
* @returns Promise with object containing user data or null, and error if any
|
|
68
|
+
*/
|
|
69
|
+
async getUser(uid) {
|
|
70
|
+
const { data: token, error: tokenError } = await this.getCachedToken();
|
|
71
|
+
if (tokenError) {
|
|
24
72
|
return {
|
|
25
73
|
data: null,
|
|
26
|
-
error:
|
|
74
|
+
error: tokenError
|
|
27
75
|
};
|
|
28
76
|
}
|
|
29
|
-
const { data, error } = await
|
|
77
|
+
const { data, error } = await getAccountInfo({ uid }, token.access_token, this.serviceAccountKey.project_id, this.tenantId, this.fetch);
|
|
30
78
|
if (error) {
|
|
31
79
|
return {
|
|
32
80
|
data: null,
|
|
@@ -38,6 +86,21 @@ export class FirebaseAdminAuth {
|
|
|
38
86
|
error: null
|
|
39
87
|
};
|
|
40
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves user account information by email address.
|
|
91
|
+
*
|
|
92
|
+
* @param email Email address to look up
|
|
93
|
+
* @returns Promise with object containing user data or null, and error if any
|
|
94
|
+
*/
|
|
95
|
+
async getUserByEmail(email) { }
|
|
96
|
+
/**
|
|
97
|
+
* Verifies a Firebase ID token and returns the decoded payload.
|
|
98
|
+
* Optionally checks if the token has been revoked.
|
|
99
|
+
*
|
|
100
|
+
* @param idToken Firebase ID token to verify
|
|
101
|
+
* @param checkRevoked Whether to check if token has been revoked (defaults to false)
|
|
102
|
+
* @returns Promise with object containing decoded token payload or null, and error if any
|
|
103
|
+
*/
|
|
41
104
|
async verifyIdToken(idToken, checkRevoked = false) {
|
|
42
105
|
const { data: decodedIdToken, error: verifyError } = await verifyJWT(idToken, this.serviceAccountKey.project_id, this.fetch);
|
|
43
106
|
if (verifyError) {
|
|
@@ -58,8 +121,11 @@ export class FirebaseAdminAuth {
|
|
|
58
121
|
if (tokenTenantId !== this.tenantId) {
|
|
59
122
|
return {
|
|
60
123
|
data: null,
|
|
61
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.
|
|
62
|
-
|
|
124
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_TENANT_ID_INVALID, {
|
|
125
|
+
context: {
|
|
126
|
+
tokenTenantId,
|
|
127
|
+
expectedTenantId: this.tenantId
|
|
128
|
+
}
|
|
63
129
|
})
|
|
64
130
|
};
|
|
65
131
|
}
|
|
@@ -74,13 +140,13 @@ export class FirebaseAdminAuth {
|
|
|
74
140
|
if (userError) {
|
|
75
141
|
return {
|
|
76
142
|
data: null,
|
|
77
|
-
error: new
|
|
143
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_LOOKUP_FAILED, { cause: ensureError(userError) })
|
|
78
144
|
};
|
|
79
145
|
}
|
|
80
146
|
if (!user) {
|
|
81
147
|
return {
|
|
82
148
|
data: null,
|
|
83
|
-
error: new
|
|
149
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_RECORD_NOT_FOUND)
|
|
84
150
|
};
|
|
85
151
|
}
|
|
86
152
|
if (user.disabled) {
|
|
@@ -107,21 +173,22 @@ export class FirebaseAdminAuth {
|
|
|
107
173
|
error: null
|
|
108
174
|
};
|
|
109
175
|
}
|
|
110
|
-
|
|
111
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Creates a session cookie from a Firebase ID token.
|
|
178
|
+
*
|
|
179
|
+
* @param idToken Firebase ID token to convert to session cookie
|
|
180
|
+
* @param expiresIn_ms Session cookie expiration time in milliseconds
|
|
181
|
+
* @returns Promise with object containing session cookie string or null, and error if any
|
|
182
|
+
*/
|
|
183
|
+
async createSessionCookie(idToken, expiresIn_ms) {
|
|
184
|
+
const { data: token, error: getTokenError } = await this.getCachedToken();
|
|
112
185
|
if (getTokenError) {
|
|
113
186
|
return {
|
|
114
187
|
data: null,
|
|
115
188
|
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED, { cause: getTokenError })
|
|
116
189
|
};
|
|
117
190
|
}
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
data: null,
|
|
121
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_NO_TOKEN_RETURNED)
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const { data, error } = await createSessionCookie(idToken, token.access_token, this.serviceAccountKey.project_id, expiresIn, this.tenantId, this.fetch);
|
|
191
|
+
const { data, error } = await createSessionCookie(idToken, token.access_token, this.serviceAccountKey.project_id, expiresIn_ms, this.tenantId, this.fetch);
|
|
125
192
|
if (error) {
|
|
126
193
|
return {
|
|
127
194
|
data: null,
|
|
@@ -133,6 +200,14 @@ export class FirebaseAdminAuth {
|
|
|
133
200
|
error: null
|
|
134
201
|
};
|
|
135
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Verifies a Firebase session cookie and returns the decoded payload.
|
|
205
|
+
* Optionally checks if the token has been revoked.
|
|
206
|
+
*
|
|
207
|
+
* @param sessionCookie Session cookie to verify
|
|
208
|
+
* @param checkRevoked Whether to check if token has been revoked (defaults to false)
|
|
209
|
+
* @returns Promise with object containing decoded session payload or null, and error if any
|
|
210
|
+
*/
|
|
136
211
|
async verifySessionCookie(sessionCookie, checkRevoked = false) {
|
|
137
212
|
const { data, error } = await verifySessionJWT(sessionCookie, this.serviceAccountKey.project_id, this.fetch);
|
|
138
213
|
if (error) {
|
|
@@ -144,9 +219,7 @@ export class FirebaseAdminAuth {
|
|
|
144
219
|
if (!data) {
|
|
145
220
|
return {
|
|
146
221
|
data: null,
|
|
147
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SESSION_COOKIE_VERIFY_FAILED
|
|
148
|
-
cause: new Error('No data returned from session cookie verification')
|
|
149
|
-
})
|
|
222
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SESSION_COOKIE_VERIFY_FAILED)
|
|
150
223
|
};
|
|
151
224
|
}
|
|
152
225
|
// Validate tenant ID if specified
|
|
@@ -155,8 +228,11 @@ export class FirebaseAdminAuth {
|
|
|
155
228
|
if (tokenTenantId !== this.tenantId) {
|
|
156
229
|
return {
|
|
157
230
|
data: null,
|
|
158
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.
|
|
159
|
-
|
|
231
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_TENANT_ID_INVALID, {
|
|
232
|
+
context: {
|
|
233
|
+
tokenTenantId,
|
|
234
|
+
expectedTenantId: this.tenantId
|
|
235
|
+
}
|
|
160
236
|
})
|
|
161
237
|
};
|
|
162
238
|
}
|
|
@@ -171,13 +247,13 @@ export class FirebaseAdminAuth {
|
|
|
171
247
|
if (userError) {
|
|
172
248
|
return {
|
|
173
249
|
data: null,
|
|
174
|
-
error: new
|
|
250
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_LOOKUP_FAILED, { cause: ensureError(userError) })
|
|
175
251
|
};
|
|
176
252
|
}
|
|
177
253
|
if (!user) {
|
|
178
254
|
return {
|
|
179
255
|
data: null,
|
|
180
|
-
error: new
|
|
256
|
+
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_USER_RECORD_NOT_FOUND)
|
|
181
257
|
};
|
|
182
258
|
}
|
|
183
259
|
return {
|
|
@@ -185,6 +261,13 @@ export class FirebaseAdminAuth {
|
|
|
185
261
|
error: null
|
|
186
262
|
};
|
|
187
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Creates a custom Firebase authentication token for a given user.
|
|
266
|
+
*
|
|
267
|
+
* @param uid User ID to create token for
|
|
268
|
+
* @param developerClaims Optional custom claims to include in the token
|
|
269
|
+
* @returns Promise with object containing custom token string or null, and error if any
|
|
270
|
+
*/
|
|
188
271
|
async createCustomToken(uid, developerClaims = {}) {
|
|
189
272
|
const claims = this.tenantId
|
|
190
273
|
? { ...developerClaims, tenant_id: this.tenantId }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase-admin-auth.js","sourceRoot":"","sources":["../../src/auth/firebase-admin-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"firebase-admin-auth.js","sourceRoot":"","sources":["../../src/auth/firebase-admin-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,cAAc,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACH,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAqB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EACH,iBAAiB,EACjB,0BAA0B,EAC1B,WAAW,EACd,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAad;IACA;IACA;IACA;IACA;IAhBJ,UAAU,GAAG,SAAS,CAAC;IAE/B;;;;;;;;OAQG;IACH,YACY,iBAAiC,EACjC,QAAiB,EACjB,KAA+B,EAC/B,KAAmB,EACnB,SAAkB;QAJlB,sBAAiB,GAAjB,iBAAiB,CAAgB;QACjC,aAAQ,GAAR,QAAQ,CAAS;QACjB,UAAK,GAAL,KAAK,CAA0B;QAC/B,UAAK,GAAL,KAAK,CAAc;QACnB,cAAS,GAAT,SAAS,CAAS;QAE1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC;IACxD,CA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