diff --git a/.changeset/wicked-scissors-yell.md b/.changeset/wicked-scissors-yell.md new file mode 100644 index 00000000000..7005f64f8f6 --- /dev/null +++ b/.changeset/wicked-scissors-yell.md @@ -0,0 +1,5 @@ +--- +"@firebase/auth": patch +--- + +Fixed issue where requestSts wasn't including the Firebase Studio cookie in it diff --git a/packages/auth/src/api/authentication/token.test.ts b/packages/auth/src/api/authentication/token.test.ts index c30bf552720..9177b4bd4ad 100644 --- a/packages/auth/src/api/authentication/token.test.ts +++ b/packages/auth/src/api/authentication/token.test.ts @@ -95,6 +95,26 @@ describe('requestStsToken', () => { ); }); + it('should use credentials: include when using Firebase Studio', async () => { + const mock = fetch.mock(endpoint, { + 'access_token': 'new-access-token', + 'expires_in': '3600', + 'refresh_token': 'new-refresh-token' + }); + + auth._logFramework('Mythical'); + auth.emulatorConfig = { + host: 'something.cloudworkstations.dev', + port: 443, + options: { disableWarnings: false }, + protocol: 'https' + }; + await requestStsToken(auth, 'some-refresh-token'); + expect(mock.calls[0].fullRequest?.credentials).to.eq('include'); + + auth.emulatorConfig = null; + }); + it('should include whatever headers come from auth impl', async () => { sinon.stub(auth, '_getAdditionalHeaders').returns( Promise.resolve({ diff --git a/packages/auth/src/api/authentication/token.ts b/packages/auth/src/api/authentication/token.ts index 6646321fbe0..478e9451e8b 100644 --- a/packages/auth/src/api/authentication/token.ts +++ b/packages/auth/src/api/authentication/token.ts @@ -17,7 +17,7 @@ /* eslint-disable camelcase */ -import { querystring } from '@firebase/util'; +import { isCloudWorkstation, querystring } from '@firebase/util'; import { _getFinalTarget, @@ -84,11 +84,18 @@ export async function requestStsToken( const headers = await (auth as AuthInternal)._getAdditionalHeaders(); headers[HttpHeader.CONTENT_TYPE] = 'application/x-www-form-urlencoded'; - return FetchProvider.fetch()(url, { + const options: RequestInit = { method: HttpMethod.POST, headers, body - }); + }; + if ( + auth.emulatorConfig && + isCloudWorkstation(auth.emulatorConfig.host) + ) { + options.credentials = 'include'; + } + return FetchProvider.fetch()(url, options); } );