@@ -154,6 +154,9 @@ export class BaseAuth {
154154 * for code samples and detailed documentation.
155155 *
156156 * @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.
157160 *
158161 * @returns A promise fulfilled with the user
159162 * data corresponding to the provided `uid`.
@@ -162,41 +165,6 @@ export class BaseAuth {
162165 return await this . authApiClient . getAccountInfoByUid ( uid , env ) ;
163166 }
164167
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-
200168 /**
201169 * Revokes all refresh tokens for an existing user.
202170 *
@@ -212,6 +180,9 @@ export class BaseAuth {
212180 *
213181 * @param uid - The `uid` corresponding to the user whose refresh tokens
214182 * 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.
215186 *
216187 * @returns An empty promise fulfilled once the user's refresh
217188 * tokens have been revoked.
@@ -240,12 +211,50 @@ export class BaseAuth {
240211 * user's ID token which is transmitted on every authenticated request.
241212 * For profile non-access related user attributes, use database or other
242213 * 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.
243217 * @returns A promise that resolves when the operation completes
244218 * successfully.
245219 */
246220 public async setCustomUserClaims ( uid : string , customUserClaims : object | null , env ?: EmulatorEnv ) : Promise < void > {
247221 await this . authApiClient . setCustomUserClaims ( uid , customUserClaims , env ) ;
248222 }
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+ }
249258}
250259
251260/**
0 commit comments