Skip to content

Commit 76401b8

Browse files
committed
BYO-CIAM Demo App Changes
1 parent 16653de commit 76401b8

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

packages/auth/demo/public/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@
170170
Action Code Settings
171171
</a>
172172
</li>
173+
<li role="presentation">
174+
<a href="#tab-byo-ciam-content"
175+
aria-controls="tab-byo-ciam-content"
176+
data-toggle="tab" role="tab">
177+
BYO-CIAM methods
178+
</a>
179+
</li>
173180
<li role="presentation" class="visible-xs">
174181
<a href="#logs-section"
175182
aria-controls="logs-section"
@@ -844,6 +851,16 @@
844851
id="action-code-settings-reset">Reset</button>
845852
</form>
846853
</div>
854+
<div class="tab-pane" id="tab-byo-ciam-content">
855+
<h2>Sign in with your CIAM token</h2>
856+
<input type="text" id="byo-ciam-token"
857+
class="form-control" placeholder="Enter CIAM token" />
858+
<button class="btn btn-block btn-primary"
859+
id="exchange-token">
860+
Exchange Token
861+
</button>
862+
<pre id="byo-ciam-result"></pre>
863+
</div>
847864
<div class="tab-pane" id="logs-section">
848865
<pre class="well logs"></pre>
849866
<button class="btn btn-xs btn-default pull-right clear-logs">

packages/auth/demo/src/index.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ import {
7474
connectAuthEmulator,
7575
initializeRecaptchaConfig,
7676
validatePassword,
77-
revokeAccessToken
77+
revokeAccessToken,
78+
exchangeToken
7879
} from '@firebase/auth';
7980

8081
import { config } from './config';
@@ -95,6 +96,7 @@ const AUTH_EMULATOR_URL = 'http://localhost:9099';
9596

9697
let app = null;
9798
let auth = null;
99+
let regionalAuth = null;
98100
let currentTab = null;
99101
let lastUser = null;
100102
let applicationVerifier = null;
@@ -1506,6 +1508,32 @@ function onFinalizeSignInWithTotpMultiFactor(event) {
15061508
}, onAuthError);
15071509
}
15081510

1511+
async function exchangeCIAMToken(token) {
1512+
const firebaseToken = await exchangeToken(
1513+
regaionalAuth,
1514+
idpConfigId = "Bar-e2e-idpconfig-002",
1515+
token)
1516+
return firebaseToken;
1517+
}
1518+
1519+
function onExchangeToken(event) {
1520+
event.preventDefault();
1521+
const byoCiamInput = document.getElementById("byo-ciam-token");
1522+
const byoCiamSubmit = document.getElementById("byo-ciam-submit");
1523+
const byoCiamResult = document.getElementById("byo-ciam-result");
1524+
1525+
byoCiamResult.textContent = "Exchanging token...";
1526+
1527+
exchangeCIAMToken(byoCiamInput.value)
1528+
.then((response) => {
1529+
byoCiamResult.textContent = response.accessToken;
1530+
console.log("Token:", response);
1531+
})
1532+
.catch((error) => {
1533+
console.error("Error exchanging token:", error);
1534+
});
1535+
}
1536+
15091537
/**
15101538
* Adds a new row to insert an OAuth custom parameter key/value pair.
15111539
* @param {!jQuery.Event} _event The jQuery event object.
@@ -2051,6 +2079,21 @@ function initApp() {
20512079
connectAuthEmulator(auth, AUTH_EMULATOR_URL);
20522080
}
20532081

2082+
let tenantConfig = {
2083+
"location": "global",
2084+
"tenantId": "Foo-e2e-tenant-001"
2085+
};
2086+
const regionalApp = initializeApp(
2087+
config,
2088+
`${auth.name}-rgcip`
2089+
);
2090+
2091+
regionalAuth = initializeAuth(regionalApp, {
2092+
persistence: inMemoryPersistence,
2093+
popupRedirectResolver: browserPopupRedirectResolver,
2094+
tenantConfig: tenantConfig
2095+
});
2096+
20542097
tempApp = initializeApp(
20552098
{
20562099
apiKey: config.apiKey,
@@ -2391,6 +2434,11 @@ function initApp() {
23912434
$('#enroll-mfa-totp-finalize').click(onFinalizeEnrollWithTotpMultiFactor);
23922435
// Sets tenant for the current auth instance
23932436
$('#set-tenant-btn').click(onSetTenantIdClick);
2437+
2438+
// Performs Exchange Token
2439+
$('#exchange-token').click(
2440+
onExchangeToken
2441+
);
23942442
}
23952443

23962444
$(initApp);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const enum DefaultConfig {
9595
API_HOST = 'identitytoolkit.googleapis.com',
9696
API_SCHEME = 'https',
9797
// TODO(sammansi): Update the endpoint before BYO-CIAM Private Preview Release.
98-
REGIONAL_API_HOST = 'identityplatform.googleapis.com/v2alpha/'
98+
REGIONAL_API_HOST = 'autopush-identityplatform.sandbox.googleapis.com/v2alpha/'
9999
}
100100

101101
export class AuthImpl implements AuthInternal, _FirebaseService {

0 commit comments

Comments
 (0)