Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove gapi.auth fall back option for getAuthToken() #7100

Merged
merged 4 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/plenty-radios-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/firestore': patch
'firebase': patch
---

Remove the deprecated gapi.auth from FirstPartyToken.
37 changes: 7 additions & 30 deletions packages/firestore/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export type AuthTokenFactory = () => string;

export interface FirstPartyCredentialsSettings {
// These are external types. Prevent minification.
['type']: 'gapi';
['client']: unknown;
['type']: 'firstParty';
['sessionIndex']: string;
['iamToken']: string | null;
['authTokenFactory']: AuthTokenFactory | null;
Expand Down Expand Up @@ -379,15 +378,6 @@ export class FirebaseAuthCredentialsProvider
}
}

// Manual type definition for the subset of Gapi we use.
interface Gapi {
auth: {
getAuthHeaderValueForFirstParty: (
userIdentifiers: Array<{ [key: string]: string }>
) => string | null;
};
}

/*
* FirstPartyToken provides a fresh token each time its value
* is requested, because if the token is too old, requests will be rejected.
Expand All @@ -401,28 +391,20 @@ export class FirstPartyToken implements Token {
private _headers = new Map();

constructor(
private readonly gapi: Gapi | null,
private readonly sessionIndex: string,
private readonly iamToken: string | null,
private readonly authTokenFactory: AuthTokenFactory | null
) {}

/** Gets an authorization token, using a provided factory function, or falling back to First Party GAPI. */
/**
* Gets an authorization token, using a provided factory function, or return
* null.
*/
private getAuthToken(): string | null {
if (this.authTokenFactory) {
return this.authTokenFactory();
} else {
// Make sure this really is a Gapi client.
hardAssert(
!!(
typeof this.gapi === 'object' &&
this.gapi !== null &&
this.gapi['auth'] &&
this.gapi['auth']['getAuthHeaderValueForFirstParty']
),
'unexpected gapi interface'
);
return this.gapi!['auth']['getAuthHeaderValueForFirstParty']([]);
return null;
}
}

Expand Down Expand Up @@ -450,7 +432,6 @@ export class FirstPartyAuthCredentialsProvider
implements CredentialsProvider<User>
{
constructor(
private gapi: Gapi | null,
private sessionIndex: string,
private iamToken: string | null,
private authTokenFactory: AuthTokenFactory | null
Expand All @@ -459,7 +440,6 @@ export class FirstPartyAuthCredentialsProvider
getToken(): Promise<Token | null> {
return Promise.resolve(
new FirstPartyToken(
this.gapi,
this.sessionIndex,
this.iamToken,
this.authTokenFactory
Expand Down Expand Up @@ -668,12 +648,9 @@ export function makeAuthCredentialsProvider(
if (!credentials) {
return new EmptyAuthCredentialsProvider();
}

switch (credentials['type']) {
case 'gapi':
const client = credentials['client'] as Gapi;
case 'firstParty':
return new FirstPartyAuthCredentialsProvider(
client,
credentials['sessionIndex'] || '0',
credentials['iamToken'] || null,
credentials['authTokenFactory'] || null
Expand Down