Skip to content

Commit fee6150

Browse files
author
Grace Benz
committed
Add support for passing in iamToken
1 parent 8ba98cb commit fee6150

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

packages/firestore/src/api/credentials.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface FirstPartyCredentialsSettings {
3434
['type']: 'gapi';
3535
['client']: unknown;
3636
['sessionIndex']: string;
37+
['iamToken']: string;
3738
}
3839

3940
export interface ProviderCredentialsSettings {
@@ -292,7 +293,13 @@ export class FirstPartyToken implements Token {
292293
type = 'FirstParty' as TokenType;
293294
user = User.FIRST_PARTY;
294295

295-
constructor(private gapi: Gapi, private sessionIndex: string) {}
296+
constructor(
297+
private gapi: Gapi,
298+
private sessionIndex: string,
299+
private iamToken: string
300+
) {
301+
console.log('bingo!! this is the token', iamToken);
302+
}
296303

297304
get authHeaders(): { [header: string]: string } {
298305
const headers: { [header: string]: string } = {
@@ -303,6 +310,9 @@ export class FirstPartyToken implements Token {
303310
if (authHeader) {
304311
headers['Authorization'] = authHeader;
305312
}
313+
if (this.iamToken) {
314+
headers['X-Goog-Iam-Authorization-Token'] = this.iamToken;
315+
}
306316
return headers;
307317
}
308318
}
@@ -313,10 +323,16 @@ export class FirstPartyToken implements Token {
313323
* to applications hosted by Google.
314324
*/
315325
export class FirstPartyCredentialsProvider implements CredentialsProvider {
316-
constructor(private gapi: Gapi, private sessionIndex: string) {}
326+
constructor(
327+
private gapi: Gapi,
328+
private sessionIndex: string,
329+
private iamToken: string
330+
) {}
317331

318332
getToken(): Promise<Token | null> {
319-
return Promise.resolve(new FirstPartyToken(this.gapi, this.sessionIndex));
333+
return Promise.resolve(
334+
new FirstPartyToken(this.gapi, this.sessionIndex, this.iamToken)
335+
);
320336
}
321337

322338
setChangeListener(changeListener: CredentialChangeListener): void {
@@ -355,7 +371,8 @@ export function makeCredentialsProvider(
355371
);
356372
return new FirstPartyCredentialsProvider(
357373
client,
358-
credentials['sessionIndex'] || '0'
374+
credentials['sessionIndex'] || '0',
375+
credentials['iamToken'] || ''
359376
);
360377

361378
case 'provider':

0 commit comments

Comments
 (0)