@quatrain/auth-firebase 1.2.7 → 1.2.9-pr25.6628
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.
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,7 +13,6 @@ exports.FirebaseAuthAdapter = void 0;
|
|
|
46
13
|
const auth_1 = require("@quatrain/auth");
|
|
47
14
|
const auth_2 = require("firebase-admin/auth");
|
|
48
15
|
const app_1 = require("firebase-admin/app");
|
|
49
|
-
const nativeFetch = __importStar(require("node-fetch-native"));
|
|
50
16
|
/**
|
|
51
17
|
* Authentication adapter implementing the Google Firebase Auth ecosystem.
|
|
52
18
|
* Handles server-side validation of JWTs and admin functions via `firebase-admin`.
|
|
@@ -186,7 +152,7 @@ class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
186
152
|
auth_1.Auth.warn(`Can't get refresh token, no API key provided`);
|
|
187
153
|
return {};
|
|
188
154
|
}
|
|
189
|
-
const response = yield
|
|
155
|
+
const response = yield fetch(`https://securetoken.googleapis.com/v1/token?key=${this._params.config.apiKey}`, {
|
|
190
156
|
method: 'POST',
|
|
191
157
|
body: JSON.stringify({
|
|
192
158
|
grant_type: 'refresh_token',
|
|
@@ -221,7 +187,7 @@ class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
221
187
|
handleCodeInApp: true,
|
|
222
188
|
};
|
|
223
189
|
}
|
|
224
|
-
const response = yield
|
|
190
|
+
const response = yield fetch(`https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=${this._params.config.apiKey}`, {
|
|
225
191
|
method: 'POST',
|
|
226
192
|
body: JSON.stringify(body),
|
|
227
193
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,17 +13,16 @@ const FirebaseAuthAdapter_1 = require("./FirebaseAuthAdapter");
|
|
|
46
13
|
const auth_1 = require("@quatrain/auth");
|
|
47
14
|
const auth_2 = require("firebase-admin/auth");
|
|
48
15
|
const app_1 = require("firebase-admin/app");
|
|
49
|
-
const nativeFetch = __importStar(require("node-fetch-native"));
|
|
50
16
|
// Mock the dependencies
|
|
51
17
|
jest.mock('firebase-admin/auth');
|
|
52
18
|
jest.mock('firebase-admin/app');
|
|
53
|
-
jest.mock('node-fetch-native');
|
|
54
19
|
describe('FirebaseAuthAdapter', () => {
|
|
55
20
|
let adapter;
|
|
56
21
|
let mockAuth;
|
|
57
22
|
beforeEach(() => {
|
|
58
23
|
// Clear all mocks before each test
|
|
59
24
|
jest.clearAllMocks();
|
|
25
|
+
global.fetch = jest.fn();
|
|
60
26
|
// Mock Firebase Admin SDK
|
|
61
27
|
mockAuth = {
|
|
62
28
|
createUser: jest.fn(),
|
|
@@ -237,9 +203,9 @@ describe('FirebaseAuthAdapter', () => {
|
|
|
237
203
|
const mockFetchResponse = {
|
|
238
204
|
json: jest.fn().mockResolvedValue(mockResponse),
|
|
239
205
|
};
|
|
240
|
-
|
|
206
|
+
global.fetch.mockResolvedValue(mockFetchResponse);
|
|
241
207
|
const result = yield adapter.refreshToken('old-refresh-token');
|
|
242
|
-
expect(
|
|
208
|
+
expect(global.fetch).toHaveBeenCalledWith('https://securetoken.googleapis.com/v1/token?key=test-api-key', {
|
|
243
209
|
method: 'POST',
|
|
244
210
|
body: JSON.stringify({
|
|
245
211
|
grant_type: 'refresh_token',
|
|
@@ -259,15 +225,15 @@ describe('FirebaseAuthAdapter', () => {
|
|
|
259
225
|
});
|
|
260
226
|
const result = yield adapterWithoutKey.refreshToken('refresh-token');
|
|
261
227
|
expect(result).toEqual({});
|
|
262
|
-
expect(
|
|
228
|
+
expect(global.fetch).not.toHaveBeenCalled();
|
|
263
229
|
}));
|
|
264
230
|
it('should construct correct URL with API key', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
231
|
const mockFetchResponse = {
|
|
266
232
|
json: jest.fn().mockResolvedValue({}),
|
|
267
233
|
};
|
|
268
|
-
|
|
234
|
+
global.fetch.mockResolvedValue(mockFetchResponse);
|
|
269
235
|
yield adapter.refreshToken('refresh-token');
|
|
270
|
-
const callArgs =
|
|
236
|
+
const callArgs = global.fetch.mock.calls[0];
|
|
271
237
|
expect(callArgs[0]).toBe('https://securetoken.googleapis.com/v1/token?key=test-api-key');
|
|
272
238
|
}));
|
|
273
239
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/auth-firebase",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9-pr25.6628",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,15 +19,14 @@
|
|
|
19
19
|
},
|
|
20
20
|
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@quatrain/core": "^1.2.
|
|
22
|
+
"@quatrain/core": "^1.2.18"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@quatrain/api": "^1.1.
|
|
26
|
-
"@quatrain/auth": "^1.2.
|
|
27
|
-
"@quatrain/backend": "^1.2.
|
|
28
|
-
"@quatrain/core": "^1.2.
|
|
29
|
-
"firebase-admin": "^13.0.1"
|
|
30
|
-
"node-fetch-native": "^1.6.4"
|
|
25
|
+
"@quatrain/api": "^1.1.7",
|
|
26
|
+
"@quatrain/auth": "^1.2.11",
|
|
27
|
+
"@quatrain/backend": "^1.2.17",
|
|
28
|
+
"@quatrain/core": "^1.2.18",
|
|
29
|
+
"firebase-admin": "^13.0.1"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
32
|
"@tsconfig/recommended": "^1.0.1",
|
|
@@ -3,12 +3,10 @@ import { User } from '@quatrain/backend'
|
|
|
3
3
|
import { AuthenticationError } from '@quatrain/auth'
|
|
4
4
|
import { getAuth } from 'firebase-admin/auth'
|
|
5
5
|
import { getApps, initializeApp } from 'firebase-admin/app'
|
|
6
|
-
import * as nativeFetch from 'node-fetch-native'
|
|
7
6
|
|
|
8
7
|
// Mock the dependencies
|
|
9
8
|
jest.mock('firebase-admin/auth')
|
|
10
9
|
jest.mock('firebase-admin/app')
|
|
11
|
-
jest.mock('node-fetch-native')
|
|
12
10
|
|
|
13
11
|
describe('FirebaseAuthAdapter', () => {
|
|
14
12
|
let adapter: FirebaseAuthAdapter
|
|
@@ -17,6 +15,7 @@ describe('FirebaseAuthAdapter', () => {
|
|
|
17
15
|
beforeEach(() => {
|
|
18
16
|
// Clear all mocks before each test
|
|
19
17
|
jest.clearAllMocks()
|
|
18
|
+
global.fetch = jest.fn()
|
|
20
19
|
|
|
21
20
|
// Mock Firebase Admin SDK
|
|
22
21
|
mockAuth = {
|
|
@@ -263,11 +262,11 @@ describe('FirebaseAuthAdapter', () => {
|
|
|
263
262
|
json: jest.fn().mockResolvedValue(mockResponse),
|
|
264
263
|
}
|
|
265
264
|
|
|
266
|
-
;(
|
|
265
|
+
;(global.fetch as unknown as jest.Mock).mockResolvedValue(mockFetchResponse)
|
|
267
266
|
|
|
268
267
|
const result = await adapter.refreshToken('old-refresh-token')
|
|
269
268
|
|
|
270
|
-
expect(
|
|
269
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
271
270
|
'https://securetoken.googleapis.com/v1/token?key=test-api-key',
|
|
272
271
|
{
|
|
273
272
|
method: 'POST',
|
|
@@ -294,7 +293,7 @@ describe('FirebaseAuthAdapter', () => {
|
|
|
294
293
|
const result = await adapterWithoutKey.refreshToken('refresh-token')
|
|
295
294
|
|
|
296
295
|
expect(result).toEqual({})
|
|
297
|
-
expect(
|
|
296
|
+
expect(global.fetch).not.toHaveBeenCalled()
|
|
298
297
|
})
|
|
299
298
|
|
|
300
299
|
it('should construct correct URL with API key', async () => {
|
|
@@ -302,11 +301,11 @@ describe('FirebaseAuthAdapter', () => {
|
|
|
302
301
|
json: jest.fn().mockResolvedValue({}),
|
|
303
302
|
}
|
|
304
303
|
|
|
305
|
-
;(
|
|
304
|
+
;(global.fetch as unknown as jest.Mock).mockResolvedValue(mockFetchResponse)
|
|
306
305
|
|
|
307
306
|
await adapter.refreshToken('refresh-token')
|
|
308
307
|
|
|
309
|
-
const callArgs = (
|
|
308
|
+
const callArgs = (global.fetch as unknown as jest.Mock).mock.calls[0]
|
|
310
309
|
expect(callArgs[0]).toBe(
|
|
311
310
|
'https://securetoken.googleapis.com/v1/token?key=test-api-key'
|
|
312
311
|
)
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import { CreateRequest, UpdateRequest, getAuth } from 'firebase-admin/auth'
|
|
10
10
|
import { getApps, initializeApp } from 'firebase-admin/app'
|
|
11
|
-
import * as nativeFetch from 'node-fetch-native'
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Authentication adapter implementing the Google Firebase Auth ecosystem.
|
|
@@ -149,7 +148,7 @@ export class FirebaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
149
148
|
Auth.warn(`Can't get refresh token, no API key provided`)
|
|
150
149
|
return {}
|
|
151
150
|
}
|
|
152
|
-
const response = await
|
|
151
|
+
const response = await fetch(
|
|
153
152
|
`https://securetoken.googleapis.com/v1/token?key=${this._params.config.apiKey}`,
|
|
154
153
|
{
|
|
155
154
|
method: 'POST',
|
|
@@ -190,7 +189,7 @@ export class FirebaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
|
|
193
|
-
const response = await
|
|
192
|
+
const response = await fetch(
|
|
194
193
|
`https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=${this._params.config.apiKey}`,
|
|
195
194
|
{
|
|
196
195
|
method: 'POST',
|