@@ -154,6 +154,9 @@ export class BaseAuth {
154
154
* for code samples and detailed documentation.
155
155
*
156
156
* @param uid - The `uid` corresponding to the user whose data to fetch.
157
+ * @param env - An optional parameter specifying the environment in which the function is running.
158
+ * If the function is running in an emulator environment, this should be set to `EmulatorEnv`.
159
+ * If not specified, the function will assume it is running in a production environment.
157
160
*
158
161
* @returns A promise fulfilled with the user
159
162
* data corresponding to the provided `uid`.
@@ -162,41 +165,6 @@ export class BaseAuth {
162
165
return await this . authApiClient . getAccountInfoByUid ( uid , env ) ;
163
166
}
164
167
165
- /**
166
- * Verifies the decoded Firebase issued JWT is not revoked or disabled. Returns a promise that
167
- * resolves with the decoded claims on success. Rejects the promise with revocation error if revoked
168
- * or user disabled.
169
- *
170
- * @param decodedIdToken - The JWT's decoded claims.
171
- * @param revocationErrorInfo - The revocation error info to throw on revocation
172
- * detection.
173
- * @returns A promise that will be fulfilled after a successful verification.
174
- */
175
- private async verifyDecodedJWTNotRevokedOrDisabled (
176
- decodedIdToken : FirebaseIdToken ,
177
- revocationErrorInfo : ErrorInfo ,
178
- env ?: EmulatorEnv
179
- ) : Promise < FirebaseIdToken > {
180
- // Get tokens valid after time for the corresponding user.
181
- const user = await this . getUser ( decodedIdToken . sub , env ) ;
182
- if ( user . disabled ) {
183
- throw new FirebaseAuthError ( AuthClientErrorCode . USER_DISABLED , 'The user record is disabled.' ) ;
184
- }
185
- // If no tokens valid after time available, token is not revoked.
186
- if ( user . tokensValidAfterTime ) {
187
- // Get the ID token authentication time and convert to milliseconds UTC.
188
- const authTimeUtc = decodedIdToken . auth_time * 1000 ;
189
- // Get user tokens valid after time in milliseconds UTC.
190
- const validSinceUtc = new Date ( user . tokensValidAfterTime ) . getTime ( ) ;
191
- // Check if authentication time is older than valid since time.
192
- if ( authTimeUtc < validSinceUtc ) {
193
- throw new FirebaseAuthError ( revocationErrorInfo ) ;
194
- }
195
- }
196
- // All checks above passed. Return the decoded token.
197
- return decodedIdToken ;
198
- }
199
-
200
168
/**
201
169
* Revokes all refresh tokens for an existing user.
202
170
*
@@ -212,6 +180,9 @@ export class BaseAuth {
212
180
*
213
181
* @param uid - The `uid` corresponding to the user whose refresh tokens
214
182
* are to be revoked.
183
+ * @param env - An optional parameter specifying the environment in which the function is running.
184
+ * If the function is running in an emulator environment, this should be set to `EmulatorEnv`.
185
+ * If not specified, the function will assume it is running in a production environment.
215
186
*
216
187
* @returns An empty promise fulfilled once the user's refresh
217
188
* tokens have been revoked.
@@ -240,12 +211,50 @@ export class BaseAuth {
240
211
* user's ID token which is transmitted on every authenticated request.
241
212
* For profile non-access related user attributes, use database or other
242
213
* separate storage systems.
214
+ * @param env - An optional parameter specifying the environment in which the function is running.
215
+ * If the function is running in an emulator environment, this should be set to `EmulatorEnv`.
216
+ * If not specified, the function will assume it is running in a production environment.
243
217
* @returns A promise that resolves when the operation completes
244
218
* successfully.
245
219
*/
246
220
public async setCustomUserClaims ( uid : string , customUserClaims : object | null , env ?: EmulatorEnv ) : Promise < void > {
247
221
await this . authApiClient . setCustomUserClaims ( uid , customUserClaims , env ) ;
248
222
}
223
+
224
+ /**
225
+ * Verifies the decoded Firebase issued JWT is not revoked or disabled. Returns a promise that
226
+ * resolves with the decoded claims on success. Rejects the promise with revocation error if revoked
227
+ * or user disabled.
228
+ *
229
+ * @param decodedIdToken - The JWT's decoded claims.
230
+ * @param revocationErrorInfo - The revocation error info to throw on revocation
231
+ * detection.
232
+ * @returns A promise that will be fulfilled after a successful verification.
233
+ */
234
+ private async verifyDecodedJWTNotRevokedOrDisabled (
235
+ decodedIdToken : FirebaseIdToken ,
236
+ revocationErrorInfo : ErrorInfo ,
237
+ env ?: EmulatorEnv
238
+ ) : Promise < FirebaseIdToken > {
239
+ // Get tokens valid after time for the corresponding user.
240
+ const user = await this . getUser ( decodedIdToken . sub , env ) ;
241
+ if ( user . disabled ) {
242
+ throw new FirebaseAuthError ( AuthClientErrorCode . USER_DISABLED , 'The user record is disabled.' ) ;
243
+ }
244
+ // If no tokens valid after time available, token is not revoked.
245
+ if ( user . tokensValidAfterTime ) {
246
+ // Get the ID token authentication time and convert to milliseconds UTC.
247
+ const authTimeUtc = decodedIdToken . auth_time * 1000 ;
248
+ // Get user tokens valid after time in milliseconds UTC.
249
+ const validSinceUtc = new Date ( user . tokensValidAfterTime ) . getTime ( ) ;
250
+ // Check if authentication time is older than valid since time.
251
+ if ( authTimeUtc < validSinceUtc ) {
252
+ throw new FirebaseAuthError ( revocationErrorInfo ) ;
253
+ }
254
+ }
255
+ // All checks above passed. Return the decoded token.
256
+ return decodedIdToken ;
257
+ }
249
258
}
250
259
251
260
/**
0 commit comments