Skip to content

Commit ce79f7f

Browse files
authored
remove gapi.auth fall back option for getAuthToken() (#7100)
1 parent ae22c61 commit ce79f7f

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

.changeset/plenty-radios-look.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/firestore': patch
3+
'firebase': patch
4+
---
5+
6+
Remove the deprecated gapi.auth from FirstPartyToken.

packages/firestore/src/api/credentials.ts

+7-30
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export type AuthTokenFactory = () => string;
4141

4242
export interface FirstPartyCredentialsSettings {
4343
// These are external types. Prevent minification.
44-
['type']: 'gapi';
45-
['client']: unknown;
44+
['type']: 'firstParty';
4645
['sessionIndex']: string;
4746
['iamToken']: string | null;
4847
['authTokenFactory']: AuthTokenFactory | null;
@@ -379,15 +378,6 @@ export class FirebaseAuthCredentialsProvider
379378
}
380379
}
381380

382-
// Manual type definition for the subset of Gapi we use.
383-
interface Gapi {
384-
auth: {
385-
getAuthHeaderValueForFirstParty: (
386-
userIdentifiers: Array<{ [key: string]: string }>
387-
) => string | null;
388-
};
389-
}
390-
391381
/*
392382
* FirstPartyToken provides a fresh token each time its value
393383
* is requested, because if the token is too old, requests will be rejected.
@@ -401,28 +391,20 @@ export class FirstPartyToken implements Token {
401391
private _headers = new Map();
402392

403393
constructor(
404-
private readonly gapi: Gapi | null,
405394
private readonly sessionIndex: string,
406395
private readonly iamToken: string | null,
407396
private readonly authTokenFactory: AuthTokenFactory | null
408397
) {}
409398

410-
/** Gets an authorization token, using a provided factory function, or falling back to First Party GAPI. */
399+
/**
400+
* Gets an authorization token, using a provided factory function, or return
401+
* null.
402+
*/
411403
private getAuthToken(): string | null {
412404
if (this.authTokenFactory) {
413405
return this.authTokenFactory();
414406
} else {
415-
// Make sure this really is a Gapi client.
416-
hardAssert(
417-
!!(
418-
typeof this.gapi === 'object' &&
419-
this.gapi !== null &&
420-
this.gapi['auth'] &&
421-
this.gapi['auth']['getAuthHeaderValueForFirstParty']
422-
),
423-
'unexpected gapi interface'
424-
);
425-
return this.gapi!['auth']['getAuthHeaderValueForFirstParty']([]);
407+
return null;
426408
}
427409
}
428410

@@ -450,7 +432,6 @@ export class FirstPartyAuthCredentialsProvider
450432
implements CredentialsProvider<User>
451433
{
452434
constructor(
453-
private gapi: Gapi | null,
454435
private sessionIndex: string,
455436
private iamToken: string | null,
456437
private authTokenFactory: AuthTokenFactory | null
@@ -459,7 +440,6 @@ export class FirstPartyAuthCredentialsProvider
459440
getToken(): Promise<Token | null> {
460441
return Promise.resolve(
461442
new FirstPartyToken(
462-
this.gapi,
463443
this.sessionIndex,
464444
this.iamToken,
465445
this.authTokenFactory
@@ -668,12 +648,9 @@ export function makeAuthCredentialsProvider(
668648
if (!credentials) {
669649
return new EmptyAuthCredentialsProvider();
670650
}
671-
672651
switch (credentials['type']) {
673-
case 'gapi':
674-
const client = credentials['client'] as Gapi;
652+
case 'firstParty':
675653
return new FirstPartyAuthCredentialsProvider(
676-
client,
677654
credentials['sessionIndex'] || '0',
678655
credentials['iamToken'] || null,
679656
credentials['authTokenFactory'] || null

0 commit comments

Comments
 (0)