@@ -27,6 +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 { base64Encode } from '@firebase/util' ;
30
31
31
32
const { firestore, database, storage } = firebase ;
32
33
export { firestore , database , storage } ;
@@ -157,6 +158,11 @@ export type FirebaseEmulatorOptions = {
157
158
} ;
158
159
} ;
159
160
161
+ function trimmedBase64Encode ( val : string ) : string {
162
+ // Use base64url encoding and remove padding in the end (dot characters).
163
+ return base64Encode ( val ) . replace ( / \. / g, "" ) ;
164
+ }
165
+
160
166
function createUnsecuredJwt ( token : TokenOptions , projectId ?: string ) : string {
161
167
// Unsecured JWTs use "none" as the algorithm.
162
168
const header = {
@@ -198,12 +204,11 @@ function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
198
204
// Unsecured JWTs use the empty string as a signature.
199
205
const signature = '' ;
200
206
return [
201
- base64 . encodeString ( JSON . stringify ( header ) , /*webSafe=*/ false ) ,
202
- base64 . encodeString ( JSON . stringify ( payload ) , /*webSafe=*/ false ) ,
207
+ trimmedBase64Encode ( JSON . stringify ( header ) ) ,
208
+ trimmedBase64Encode ( JSON . stringify ( payload ) ) ,
203
209
signature
204
210
] . join ( '.' ) ;
205
211
}
206
-
207
212
export function apps ( ) : firebase . app . App [ ] {
208
213
return firebase . apps ;
209
214
}
0 commit comments