@quatrain/auth-firebase 1.2.3 → 1.2.4

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.
@@ -2,8 +2,23 @@ import { User } from '@quatrain/backend';
2
2
  import { AbstractAuthAdapter, AuthParameters } from '@quatrain/auth';
3
3
  import { ApiMiddleware } from '@quatrain/api';
4
4
  import { UpdateRequest } from 'firebase-admin/auth';
5
+ /**
6
+ * Authentication adapter implementing the Google Firebase Auth ecosystem.
7
+ * Handles server-side validation of JWTs and admin functions via `firebase-admin`.
8
+ */
5
9
  export declare class FirebaseAuthAdapter extends AbstractAuthAdapter {
10
+ /**
11
+ * Bootstraps the adapter using Firebase credentials.
12
+ *
13
+ * @param config - Firebase admin SDK configuration block.
14
+ * @returns The adapter instance.
15
+ */
6
16
  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
+ */
7
22
  middleware(): ApiMiddleware;
8
23
  constructor(params?: AuthParameters);
9
24
  /**
@@ -12,12 +27,58 @@ export declare class FirebaseAuthAdapter extends AbstractAuthAdapter {
12
27
  * @returns user unique id
13
28
  */
14
29
  register(user: User, clearPassword?: string): Promise<string>;
30
+ /**
31
+ * Verifies a Firebase ID token using the admin SDK.
32
+ *
33
+ * @param bearer - The JWT token string.
34
+ * @returns A promise resolving to the decoded token object.
35
+ */
15
36
  getAuthToken(bearer: string): Promise<import("firebase-admin/auth").DecodedIdToken>;
37
+ /**
38
+ * User authentication flow (Not natively supported on Firebase Admin Server SDK).
39
+ * Usually handled on the client.
40
+ *
41
+ * @param login - Email address.
42
+ * @param password - Plain password.
43
+ */
16
44
  signup(login: string, password: string): Promise<void>;
45
+ /**
46
+ * Signs out the user (No-op in server-side stateless Firebase admin).
47
+ *
48
+ * @param user - Target user.
49
+ */
17
50
  signout(user: User): Promise<any>;
51
+ /**
52
+ * Modifies an existing user's attributes in the Firebase Auth registry.
53
+ *
54
+ * @param user - Target user.
55
+ * @param updatable - Properties to modify (e.g. displayName, disabled status).
56
+ */
18
57
  update(user: User, updatable: UpdateRequest): Promise<any>;
58
+ /**
59
+ * Completely removes a user from the Firebase Auth registry.
60
+ *
61
+ * @param user - Target user.
62
+ */
19
63
  delete(user: User): Promise<any>;
64
+ /**
65
+ * Revokes a specific access token.
66
+ *
67
+ * @param token - The token string.
68
+ */
20
69
  revokeAuthToken(token: string): Promise<void>;
70
+ /**
71
+ * Updates the custom JWT claims embedded in a user's Firebase token.
72
+ *
73
+ * @param id - User UID.
74
+ * @param claims - Claims dictionary.
75
+ */
21
76
  setCustomUserClaims(id: string, claims: any): Promise<void>;
77
+ /**
78
+ * Requests a new ID token using a refresh token via Google Secure Token API.
79
+ *
80
+ * @param refreshToken - The active refresh token.
81
+ * @returns The generated token payload.
82
+ */
22
83
  refreshToken(refreshToken: string): Promise<any>;
23
84
  }
@@ -47,10 +47,25 @@ const auth_1 = require("@quatrain/auth");
47
47
  const auth_2 = require("firebase-admin/auth");
48
48
  const app_1 = require("firebase-admin/app");
49
49
  const nativeFetch = __importStar(require("node-fetch-native"));
50
+ /**
51
+ * Authentication adapter implementing the Google Firebase Auth ecosystem.
52
+ * Handles server-side validation of JWTs and admin functions via `firebase-admin`.
53
+ */
50
54
  class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
55
+ /**
56
+ * Bootstraps the adapter using Firebase credentials.
57
+ *
58
+ * @param config - Firebase admin SDK configuration block.
59
+ * @returns The adapter instance.
60
+ */
51
61
  static factory(config) {
52
62
  return new FirebaseAuthAdapter({ config });
53
63
  }
64
+ /**
65
+ * Express middleware that intercepts and verifies incoming Firebase JWT Bearer tokens.
66
+ *
67
+ * @returns The validation middleware function.
68
+ */
54
69
  middleware() {
55
70
  return (req, res) => __awaiter(this, void 0, void 0, function* () {
56
71
  var _a;
@@ -103,17 +118,41 @@ class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
103
118
  }
104
119
  });
105
120
  }
121
+ /**
122
+ * Verifies a Firebase ID token using the admin SDK.
123
+ *
124
+ * @param bearer - The JWT token string.
125
+ * @returns A promise resolving to the decoded token object.
126
+ */
106
127
  getAuthToken(bearer) {
107
128
  return __awaiter(this, void 0, void 0, function* () {
108
129
  return yield (0, auth_2.getAuth)().verifyIdToken(bearer);
109
130
  });
110
131
  }
132
+ /**
133
+ * User authentication flow (Not natively supported on Firebase Admin Server SDK).
134
+ * Usually handled on the client.
135
+ *
136
+ * @param login - Email address.
137
+ * @param password - Plain password.
138
+ */
111
139
  signup(login, password) {
112
140
  return __awaiter(this, void 0, void 0, function* () { });
113
141
  }
142
+ /**
143
+ * Signs out the user (No-op in server-side stateless Firebase admin).
144
+ *
145
+ * @param user - Target user.
146
+ */
114
147
  signout(user) {
115
148
  return __awaiter(this, void 0, void 0, function* () { });
116
149
  }
150
+ /**
151
+ * Modifies an existing user's attributes in the Firebase Auth registry.
152
+ *
153
+ * @param user - Target user.
154
+ * @param updatable - Properties to modify (e.g. displayName, disabled status).
155
+ */
117
156
  update(user, updatable) {
118
157
  return __awaiter(this, void 0, void 0, function* () {
119
158
  auth_1.Auth.log('auth data to update', JSON.stringify(updatable));
@@ -126,17 +165,39 @@ class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
126
165
  catch (e) { }
127
166
  });
128
167
  }
168
+ /**
169
+ * Completely removes a user from the Firebase Auth registry.
170
+ *
171
+ * @param user - Target user.
172
+ */
129
173
  delete(user) {
130
174
  return __awaiter(this, void 0, void 0, function* () {
131
175
  return yield (0, auth_2.getAuth)().deleteUser(user.uid);
132
176
  });
133
177
  }
178
+ /**
179
+ * Revokes a specific access token.
180
+ *
181
+ * @param token - The token string.
182
+ */
134
183
  revokeAuthToken(token) {
135
184
  return __awaiter(this, void 0, void 0, function* () { });
136
185
  }
186
+ /**
187
+ * Updates the custom JWT claims embedded in a user's Firebase token.
188
+ *
189
+ * @param id - User UID.
190
+ * @param claims - Claims dictionary.
191
+ */
137
192
  setCustomUserClaims(id, claims) {
138
193
  return __awaiter(this, void 0, void 0, function* () { });
139
194
  }
195
+ /**
196
+ * Requests a new ID token using a refresh token via Google Secure Token API.
197
+ *
198
+ * @param refreshToken - The active refresh token.
199
+ * @returns The generated token payload.
200
+ */
140
201
  refreshToken(refreshToken) {
141
202
  return __awaiter(this, void 0, void 0, function* () {
142
203
  if (!this._params.config.apiKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-firebase",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "@quatrain/core": "^1.2.5"
23
23
  },
24
24
  "dependencies": {
25
- "@quatrain/api": "^1.1.4",
26
- "@quatrain/auth": "^1.2.1",
25
+ "@quatrain/api": "^1.1.5",
26
+ "@quatrain/auth": "^1.2.2",
27
27
  "@quatrain/backend": "^1.2.6",
28
28
  "@quatrain/core": "^1.2.5",
29
29
  "firebase-admin": "^13.0.1",
@@ -10,11 +10,26 @@ 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'
12
12
 
13
+ /**
14
+ * Authentication adapter implementing the Google Firebase Auth ecosystem.
15
+ * Handles server-side validation of JWTs and admin functions via `firebase-admin`.
16
+ */
13
17
  export class FirebaseAuthAdapter extends AbstractAuthAdapter {
18
+ /**
19
+ * Bootstraps the adapter using Firebase credentials.
20
+ *
21
+ * @param config - Firebase admin SDK configuration block.
22
+ * @returns The adapter instance.
23
+ */
14
24
  static factory(config: any): FirebaseAuthAdapter {
15
25
  return new FirebaseAuthAdapter({ config })
16
26
  }
17
27
 
28
+ /**
29
+ * Express middleware that intercepts and verifies incoming Firebase JWT Bearer tokens.
30
+ *
31
+ * @returns The validation middleware function.
32
+ */
18
33
  public middleware(): ApiMiddleware {
19
34
  return async (req: ApiRequest, res: ApiResponse): Promise<boolean> => {
20
35
  const bearer = ((req.headers?.authorization as string) || '').split(' ')[1] || ''
@@ -74,14 +89,38 @@ export class FirebaseAuthAdapter extends AbstractAuthAdapter {
74
89
  }
75
90
  }
76
91
 
92
+ /**
93
+ * Verifies a Firebase ID token using the admin SDK.
94
+ *
95
+ * @param bearer - The JWT token string.
96
+ * @returns A promise resolving to the decoded token object.
97
+ */
77
98
  async getAuthToken(bearer: string) {
78
99
  return await getAuth().verifyIdToken(bearer)
79
100
  }
80
101
 
102
+ /**
103
+ * User authentication flow (Not natively supported on Firebase Admin Server SDK).
104
+ * Usually handled on the client.
105
+ *
106
+ * @param login - Email address.
107
+ * @param password - Plain password.
108
+ */
81
109
  async signup(login: string, password: string) {}
82
110
 
111
+ /**
112
+ * Signs out the user (No-op in server-side stateless Firebase admin).
113
+ *
114
+ * @param user - Target user.
115
+ */
83
116
  async signout(user: User): Promise<any> {}
84
117
 
118
+ /**
119
+ * Modifies an existing user's attributes in the Firebase Auth registry.
120
+ *
121
+ * @param user - Target user.
122
+ * @param updatable - Properties to modify (e.g. displayName, disabled status).
123
+ */
85
124
  async update(user: User, updatable: UpdateRequest): Promise<any> {
86
125
  Auth.log('auth data to update', JSON.stringify(updatable))
87
126
 
@@ -93,14 +132,36 @@ export class FirebaseAuthAdapter extends AbstractAuthAdapter {
93
132
  } catch (e) {}
94
133
  }
95
134
 
135
+ /**
136
+ * Completely removes a user from the Firebase Auth registry.
137
+ *
138
+ * @param user - Target user.
139
+ */
96
140
  async delete(user: User): Promise<any> {
97
141
  return await getAuth().deleteUser(user.uid)
98
142
  }
99
143
 
144
+ /**
145
+ * Revokes a specific access token.
146
+ *
147
+ * @param token - The token string.
148
+ */
100
149
  async revokeAuthToken(token: string) {}
101
150
 
151
+ /**
152
+ * Updates the custom JWT claims embedded in a user's Firebase token.
153
+ *
154
+ * @param id - User UID.
155
+ * @param claims - Claims dictionary.
156
+ */
102
157
  async setCustomUserClaims(id: string, claims: any) {}
103
158
 
159
+ /**
160
+ * Requests a new ID token using a refresh token via Google Secure Token API.
161
+ *
162
+ * @param refreshToken - The active refresh token.
163
+ * @returns The generated token payload.
164
+ */
104
165
  async refreshToken(refreshToken: string): Promise<any> {
105
166
  if (!this._params.config.apiKey) {
106
167
  Auth.warn(`Can't get refresh token, no API key provided`)