Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/wicked-scissors-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Fixed issue where requestSts wasn't including the Firebase Studio cookie in it
20 changes: 20 additions & 0 deletions packages/auth/src/api/authentication/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
13 changes: 10 additions & 3 deletions packages/auth/src/api/authentication/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/* eslint-disable camelcase */

import { querystring } from '@firebase/util';
import { isCloudWorkstation, querystring } from '@firebase/util';

import {
_getFinalTarget,
Expand Down Expand Up @@ -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);
}
);

Expand Down
Loading