@quatrain/auth-firebase 1.2.4 → 1.2.5
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,6 +1,5 @@
|
|
|
1
1
|
import { User } from '@quatrain/backend';
|
|
2
2
|
import { AbstractAuthAdapter, AuthParameters } from '@quatrain/auth';
|
|
3
|
-
import { ApiMiddleware } from '@quatrain/api';
|
|
4
3
|
import { UpdateRequest } from 'firebase-admin/auth';
|
|
5
4
|
/**
|
|
6
5
|
* Authentication adapter implementing the Google Firebase Auth ecosystem.
|
|
@@ -14,12 +13,6 @@ export declare class FirebaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
14
13
|
* @returns The adapter instance.
|
|
15
14
|
*/
|
|
16
15
|
static factory(config: any): FirebaseAuthAdapter;
|
|
17
|
-
/**
|
|
18
|
-
* Express middleware that intercepts and verifies incoming Firebase JWT Bearer tokens.
|
|
19
|
-
*
|
|
20
|
-
* @returns The validation middleware function.
|
|
21
|
-
*/
|
|
22
|
-
middleware(): ApiMiddleware;
|
|
23
16
|
constructor(params?: AuthParameters);
|
|
24
17
|
/**
|
|
25
18
|
* Register new user in authentication
|
|
@@ -61,31 +61,6 @@ class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
61
61
|
static factory(config) {
|
|
62
62
|
return new FirebaseAuthAdapter({ config });
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Express middleware that intercepts and verifies incoming Firebase JWT Bearer tokens.
|
|
66
|
-
*
|
|
67
|
-
* @returns The validation middleware function.
|
|
68
|
-
*/
|
|
69
|
-
middleware() {
|
|
70
|
-
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
var _a;
|
|
72
|
-
const bearer = (((_a = req.headers) === null || _a === void 0 ? void 0 : _a.authorization) || '').split(' ')[1] || '';
|
|
73
|
-
if (bearer) {
|
|
74
|
-
try {
|
|
75
|
-
const user = yield this.getAuthToken(bearer);
|
|
76
|
-
if (user) {
|
|
77
|
-
return true; // Authorized
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
auth_1.Auth.error(`[FirebaseAuthAdapter] Middleware token verification failed: ${e.message}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
res.setHeader('WWW-Authenticate', 'Bearer realm="Core API"');
|
|
85
|
-
res.status(401).send('Authentication required.');
|
|
86
|
-
return false;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
64
|
constructor(params = {}) {
|
|
90
65
|
super(params);
|
|
91
66
|
if ((0, app_1.getApps)().length === 0 && params.config) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/auth-firebase",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,13 +19,13 @@
|
|
|
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.14"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@quatrain/api": "^1.1.5",
|
|
26
|
-
"@quatrain/auth": "^1.2.
|
|
27
|
-
"@quatrain/backend": "^1.2.
|
|
28
|
-
"@quatrain/core": "^1.2.
|
|
26
|
+
"@quatrain/auth": "^1.2.3",
|
|
27
|
+
"@quatrain/backend": "^1.2.11",
|
|
28
|
+
"@quatrain/core": "^1.2.14",
|
|
29
29
|
"firebase-admin": "^13.0.1",
|
|
30
30
|
"node-fetch-native": "^1.6.4"
|
|
31
31
|
},
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
AuthenticationError,
|
|
6
6
|
AuthParameters,
|
|
7
7
|
} from '@quatrain/auth'
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
import { CreateRequest, UpdateRequest, getAuth } from 'firebase-admin/auth'
|
|
10
10
|
import { getApps, initializeApp } from 'firebase-admin/app'
|
|
11
11
|
import * as nativeFetch from 'node-fetch-native'
|
|
@@ -25,31 +25,7 @@ export class FirebaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
25
25
|
return new FirebaseAuthAdapter({ config })
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* Express middleware that intercepts and verifies incoming Firebase JWT Bearer tokens.
|
|
30
|
-
*
|
|
31
|
-
* @returns The validation middleware function.
|
|
32
|
-
*/
|
|
33
|
-
public middleware(): ApiMiddleware {
|
|
34
|
-
return async (req: ApiRequest, res: ApiResponse): Promise<boolean> => {
|
|
35
|
-
const bearer = ((req.headers?.authorization as string) || '').split(' ')[1] || ''
|
|
36
|
-
|
|
37
|
-
if (bearer) {
|
|
38
|
-
try {
|
|
39
|
-
const user = await this.getAuthToken(bearer)
|
|
40
|
-
if (user) {
|
|
41
|
-
return true // Authorized
|
|
42
|
-
}
|
|
43
|
-
} catch(e) {
|
|
44
|
-
Auth.error(`[FirebaseAuthAdapter] Middleware token verification failed: ${(e as Error).message}`)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
28
|
|
|
48
|
-
res.setHeader('WWW-Authenticate', 'Bearer realm="Core API"')
|
|
49
|
-
res.status(401).send('Authentication required.')
|
|
50
|
-
return false
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
29
|
|
|
54
30
|
constructor(params: AuthParameters = {}) {
|
|
55
31
|
super(params)
|