22
22
23
23
import * as cors from 'cors' ;
24
24
import * as express from 'express' ;
25
- import * as firebase from 'firebase-admin' ;
25
+ import { DecodedAppCheckToken } from 'firebase-admin/app-check' ;
26
+ import { DecodedIdToken } from 'firebase-admin/auth' ;
26
27
27
28
import * as logger from '../../logger' ;
28
29
@@ -40,60 +41,6 @@ export interface Request extends express.Request {
40
41
rawBody : Buffer ;
41
42
}
42
43
43
- // This is actually a firebase.appCheck.DecodedAppCheckToken, but
44
- // that type may not be available in some supported SDK versions.
45
- // Declare as an inline type, which DecodedAppCheckToken will be
46
- // able to merge with.
47
- // TODO: Replace with the real type once we bump the min-version of
48
- // the admin SDK
49
- interface DecodedAppCheckToken {
50
- /**
51
- * The issuer identifier for the issuer of the response.
52
- *
53
- * This value is a URL with the format
54
- * `https://firebaseappcheck.googleapis.com/<PROJECT_NUMBER>`, where `<PROJECT_NUMBER>` is the
55
- * same project number specified in the [`aud`](#aud) property.
56
- */
57
- iss : string ;
58
-
59
- /**
60
- * The Firebase App ID corresponding to the app the token belonged to.
61
- *
62
- * As a convenience, this value is copied over to the [`app_id`](#app_id) property.
63
- */
64
- sub : string ;
65
-
66
- /**
67
- * The audience for which this token is intended.
68
- *
69
- * This value is a JSON array of two strings, the first is the project number of your
70
- * Firebase project, and the second is the project ID of the same project.
71
- */
72
- aud : string [ ] ;
73
-
74
- /**
75
- * The App Check token's expiration time, in seconds since the Unix epoch. That is, the
76
- * time at which this App Check token expires and should no longer be considered valid.
77
- */
78
- exp : number ;
79
-
80
- /**
81
- * The App Check token's issued-at time, in seconds since the Unix epoch. That is, the
82
- * time at which this App Check token was issued and should start to be considered
83
- * valid.;
84
- */
85
- iat : number ;
86
-
87
- /**
88
- * The App ID corresponding to the App the App Check token belonged to.
89
- *
90
- * This value is not actually one of the JWT token claims. It is added as a
91
- * convenience, and is set as the value of the [`sub`](#sub) property.
92
- */
93
- app_id : string ;
94
- [ key : string ] : any ;
95
- }
96
-
97
44
/**
98
45
* The interface for AppCheck tokens verified in Callable functions
99
46
*/
@@ -107,7 +54,7 @@ export interface AppCheckData {
107
54
*/
108
55
export interface AuthData {
109
56
uid : string ;
110
- token : firebase . auth . DecodedIdToken ;
57
+ token : DecodedIdToken ;
111
58
}
112
59
113
60
// This type is the direct v1 callable interface and is also an interface
@@ -553,10 +500,8 @@ export function unsafeDecodeToken(token: string): unknown {
553
500
* This is exposed only for testing.
554
501
*/
555
502
/** @internal */
556
- export function unsafeDecodeIdToken (
557
- token : string
558
- ) : firebase . auth . DecodedIdToken {
559
- const decoded = unsafeDecodeToken ( token ) as firebase . auth . DecodedIdToken ;
503
+ export function unsafeDecodeIdToken ( token : string ) : DecodedIdToken {
504
+ const decoded = unsafeDecodeToken ( token ) as DecodedIdToken ;
560
505
decoded . uid = decoded . sub ;
561
506
return decoded ;
562
507
}
@@ -642,7 +587,7 @@ export async function checkAuthToken(
642
587
if ( match ) {
643
588
const idToken = match [ 1 ] ;
644
589
try {
645
- let authToken : firebase . auth . DecodedIdToken ;
590
+ let authToken : DecodedIdToken ;
646
591
if ( isDebugFeatureEnabled ( 'skipTokenVerification' ) ) {
647
592
authToken = unsafeDecodeIdToken ( idToken ) ;
648
593
} else {
@@ -672,11 +617,6 @@ async function checkAppCheckToken(
672
617
return 'MISSING' ;
673
618
}
674
619
try {
675
- if ( ! apps ( ) . admin . appCheck ) {
676
- throw new Error (
677
- 'Cannot validate AppCheck token. Please update Firebase Admin SDK to >= v9.8.0'
678
- ) ;
679
- }
680
620
let appCheckData ;
681
621
if ( isDebugFeatureEnabled ( 'skipTokenVerification' ) ) {
682
622
const decodedToken = unsafeDecodeAppCheckToken ( appCheck ) ;
0 commit comments