Skip to content

Commit 96a2b28

Browse files
committed
Implement signout() for BYO-CIAM
1 parent 5616d78 commit 96a2b28

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

.github/workflows/test-all.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env:
2323
# the behavior to use the new URLs.
2424
CHROMEDRIVER_CDNURL: https://googlechromelabs.github.io/
2525
CHROMEDRIVER_CDNBINARIESURL: https://storage.googleapis.com/chrome-for-testing-public
26-
CHROME_VALIDATED_VERSION: linux-137.0.0.0
26+
CHROME_VALIDATED_VERSION: linux-132.0.6834.110
2727
CHROME_VERSION_MISMATCH_MESSAGE: "The Chrome version doesn't match the previously validated version. Consider updating CHROME_VALIDATED_VERSION in the GitHub workflow if tests pass, or rollback the installed Chrome version if tests fail."
2828
artifactRetentionDays: 14
2929
# Bump Node memory limit

packages/auth/demo/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@
853853
</div>
854854
<div class="tab-pane" id="tab-byo-ciam-content">
855855
<h2>Sign in with your CIAM token</h2>
856+
<div id="firebase-token-status">No CIAM token found. User not logged in.</div>
856857
<input type="text" id="byo-ciam-token"
857858
class="form-control" placeholder="Enter CIAM token" />
858859
<button class="btn btn-block btn-primary"

packages/auth/demo/src/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ function onRefreshToken() {
13051305
function onSignOut() {
13061306
setLastUser(auth.currentUser);
13071307
auth.signOut().then(signOut, onAuthError);
1308+
regionalAuth.signOut();
13081309
}
13091310

13101311
/**
@@ -1520,16 +1521,17 @@ async function exchangeCIAMToken(token) {
15201521
function onExchangeToken(event) {
15211522
event.preventDefault();
15221523
const byoCiamInput = document.getElementById('byo-ciam-token');
1523-
const byoCiamResult = document.getElementById('byo-ciam-result');
1524+
const firebaseTokenStatus = document.getElementById('firebase-token-status');
15241525

1525-
byoCiamResult.textContent = 'Exchanging token...';
1526+
firebaseTokenStatus.textContent = 'Exchanging token...';
15261527

15271528
exchangeCIAMToken(byoCiamInput.value)
15281529
.then(response => {
1529-
byoCiamResult.textContent = response;
1530+
firebaseTokenStatus.textContent = '✅ Firebase token is set: ' + response;
15301531
console.log('Token:', response);
15311532
})
15321533
.catch(error => {
1534+
(firebaseTokenStatus.textContent = 'Error exchanging token: '), error;
15331535
console.error('Error exchanging token:', error);
15341536
});
15351537
}
@@ -2091,6 +2093,18 @@ function initApp() {
20912093
tenantConfig: tenantConfig
20922094
});
20932095

2096+
const firebaseTokenStatus = document.getElementById('firebase-token-status');
2097+
setTimeout(() => {
2098+
if (regionalAuth.firebaseToken) {
2099+
firebaseTokenStatus.textContent =
2100+
'✅ Firebase token is set: ' + regionalAuth.firebaseToken.token;
2101+
} else {
2102+
firebaseTokenStatus.textContent =
2103+
'No CIAM token found. User not logged in.';
2104+
}
2105+
console.log('firebaseToken after delay: ', regionalAuth.firebaseToken);
2106+
}, 1000);
2107+
20942108
tempApp = initializeApp(
20952109
{
20962110
apiKey: config.apiKey,

packages/auth/src/core/auth/auth_impl.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
FAKE_APP_CHECK_CONTROLLER_PROVIDER,
2929
FAKE_HEARTBEAT_CONTROLLER,
3030
FAKE_HEARTBEAT_CONTROLLER_PROVIDER,
31+
regionalTestAuth,
3132
testAuth,
3233
testUser
3334
} from '../../../test/helpers/mock_auth';
@@ -308,6 +309,17 @@ describe('core/auth/auth_impl', () => {
308309
expect(persistenceStub._remove).to.have.been.called;
309310
expect(auth.currentUser).to.be.null;
310311
});
312+
it('sets currentUser to null, calls remove', async () => {
313+
const regionalAuth = await regionalTestAuth();
314+
const token: FirebaseToken = {
315+
token: 'test-token',
316+
expirationTime: 123456789
317+
};
318+
await regionalAuth._updateFirebaseToken(token);
319+
await regionalAuth.signOut();
320+
expect(persistenceStub._remove).to.have.been.called;
321+
expect(regionalAuth.firebaseToken).to.be.null;
322+
});
311323
it('is blocked if a beforeAuthStateChanged callback throws', async () => {
312324
await auth._updateCurrentUser(testUser(auth, 'test'));
313325
auth.beforeAuthStateChanged(sinon.stub().throws());

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
489489
if (this.redirectPersistenceManager || this._popupRedirectResolver) {
490490
await this._setRedirectUser(null);
491491
}
492-
492+
if (this.tenantConfig) {
493+
await this._updateFirebaseToken(null);
494+
}
493495
// Prevent callbacks from being called again in _updateCurrentUser, as
494496
// they were already called in the first line.
495497
return this._updateCurrentUser(null, /* skipBeforeStateCallbacks */ true);

0 commit comments

Comments
 (0)