Skip to content

Commit c0617a3

Browse files
authored
Fixed issue where requestSts wasn't including the Studio cookie in it (#9075)
1 parent 6cc9a07 commit c0617a3

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.changeset/wicked-scissors-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fixed issue where requestSts wasn't including the Firebase Studio cookie in it

packages/auth/src/api/authentication/token.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ describe('requestStsToken', () => {
9595
);
9696
});
9797

98+
it('should use credentials: include when using Firebase Studio', async () => {
99+
const mock = fetch.mock(endpoint, {
100+
'access_token': 'new-access-token',
101+
'expires_in': '3600',
102+
'refresh_token': 'new-refresh-token'
103+
});
104+
105+
auth._logFramework('Mythical');
106+
auth.emulatorConfig = {
107+
host: 'something.cloudworkstations.dev',
108+
port: 443,
109+
options: { disableWarnings: false },
110+
protocol: 'https'
111+
};
112+
await requestStsToken(auth, 'some-refresh-token');
113+
expect(mock.calls[0].fullRequest?.credentials).to.eq('include');
114+
115+
auth.emulatorConfig = null;
116+
});
117+
98118
it('should include whatever headers come from auth impl', async () => {
99119
sinon.stub(auth, '_getAdditionalHeaders').returns(
100120
Promise.resolve({

packages/auth/src/api/authentication/token.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/* eslint-disable camelcase */
1919

20-
import { querystring } from '@firebase/util';
20+
import { isCloudWorkstation, querystring } from '@firebase/util';
2121

2222
import {
2323
_getFinalTarget,
@@ -84,11 +84,18 @@ export async function requestStsToken(
8484
const headers = await (auth as AuthInternal)._getAdditionalHeaders();
8585
headers[HttpHeader.CONTENT_TYPE] = 'application/x-www-form-urlencoded';
8686

87-
return FetchProvider.fetch()(url, {
87+
const options: RequestInit = {
8888
method: HttpMethod.POST,
8989
headers,
9090
body
91-
});
91+
};
92+
if (
93+
auth.emulatorConfig &&
94+
isCloudWorkstation(auth.emulatorConfig.host)
95+
) {
96+
options.credentials = 'include';
97+
}
98+
return FetchProvider.fetch()(url, options);
9299
}
93100
);
94101

0 commit comments

Comments
 (0)