@@ -27,7 +27,7 @@ import * as request from 'request';
27
27
import { base64 } from '@firebase/util' ;
28
28
import { setLogLevel , LogLevel } from '@firebase/logger' ;
29
29
import { Component , ComponentType } from '@firebase/component' ;
30
- import * as jwt from 'jsonwebtoken ' ;
30
+ import { base64Encode } from '@firebase/util ' ;
31
31
32
32
const { firestore, database, storage } = firebase ;
33
33
export { firestore , database , storage } ;
@@ -159,19 +159,20 @@ export type FirebaseEmulatorOptions = {
159
159
} ;
160
160
161
161
function createUnsecuredJwt ( token : TokenOptions , projectId ?: string ) : string {
162
+ // Unsecured JWTs use "none" as the algorithm.
163
+ const header = {
164
+ alg : 'none' ,
165
+ kid : 'fakekid' ,
166
+ type : 'JWT'
167
+ } ;
168
+
162
169
const project = projectId || 'fake-project' ;
163
170
const iat = token . iat || 0 ;
164
171
const uid = token . sub || token . uid || token . user_id ;
165
172
if ( ! uid ) {
166
173
throw new Error ( "Auth must contain 'sub', 'uid', or 'user_id' field!" ) ;
167
174
}
168
175
169
- const header = {
170
- alg : 'none' ,
171
- kid : 'fakekid' ,
172
- type : 'JWT'
173
- } ;
174
-
175
176
const payload : FirebaseIdToken = {
176
177
// Set all required fields to decent defaults
177
178
iss : `https://securetoken.google.com/${ project } ` ,
@@ -197,9 +198,12 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
197
198
198
199
// Unsecured JWTs use the empty string as a signature.
199
200
const signature = '' ;
200
- return jwt . sign ( payload , signature , { algorithm : 'none' , header } ) ;
201
+ return [
202
+ base64Encode ( JSON . stringify ( header ) ) ,
203
+ base64Encode ( JSON . stringify ( payload ) ) ,
204
+ signature
205
+ ] . join ( '.' ) ;
201
206
}
202
-
203
207
export function apps ( ) : firebase . app . App [ ] {
204
208
return firebase . apps ;
205
209
}
0 commit comments