Skip to content

Commit 36b31af

Browse files
authored
Merge 70d6f9b into 1aa8468
2 parents 1aa8468 + 70d6f9b commit 36b31af

File tree

10 files changed

+89
-18
lines changed

10 files changed

+89
-18
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: 47 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,24 @@ function onFinalizeSignInWithTotpMultiFactor(event) {
15061508
}, onAuthError);
15071509
}
15081510

1511+
function onExchangeToken(event) {
1512+
event.preventDefault();
1513+
const byoCiamInput = document.getElementById("byo-ciam-token");
1514+
const byoCiamSubmit = document.getElementById("byo-ciam-submit");
1515+
const byoCiamResult = document.getElementById("byo-ciam-result");
1516+
1517+
byoCiamResult.textContent = "Exchanging token...";
1518+
1519+
exchangeCIAMToken(byoCiamInput.value)
1520+
.then((response) => {
1521+
byoCiamResult.textContent = response.accessToken;
1522+
console.log("Token:", response);
1523+
})
1524+
.catch((error) => {
1525+
console.error("Error exchanging token:", error);
1526+
});
1527+
}
1528+
15091529
/**
15101530
* Adds a new row to insert an OAuth custom parameter key/value pair.
15111531
* @param {!jQuery.Event} _event The jQuery event object.
@@ -1795,6 +1815,14 @@ function revokeAppleTokenAndDeleteUser() {
17951815
});
17961816
}
17971817

1818+
async function exchangeCIAMToken(token) {
1819+
const firebaseToken = await exchangeToken(
1820+
regaionalAuth,
1821+
idpConfigId = "Bar-e2e-idpconfig-002",
1822+
token)
1823+
return firebaseToken;
1824+
}
1825+
17981826
/**
17991827
* Gets a specific query parameter from the current URL.
18001828
* @param {string} name Name of the parameter.
@@ -2047,6 +2075,20 @@ function initApp() {
20472075
log('Initializing app...');
20482076
app = initializeApp(config);
20492077
auth = getAuth(app);
2078+
let tenantConfig = {
2079+
"location": "global",
2080+
"tenantId": "Foo-e2e-tenant-001"
2081+
};
2082+
const regionalApp = initializeApp(
2083+
config,
2084+
`${auth.name}-rgcip`
2085+
);
2086+
2087+
regaionalAuth = initializeAuth(regionalApp, {
2088+
persistence: inMemoryPersistence,
2089+
popupRedirectResolver: browserPopupRedirectResolver,
2090+
tenantConfig: tenantConfig
2091+
});
20502092
if (USE_AUTH_EMULATOR) {
20512093
connectAuthEmulator(auth, AUTH_EMULATOR_URL);
20522094
}
@@ -2379,6 +2421,10 @@ function initApp() {
23792421
onFinalizeSignInWithTotpMultiFactor
23802422
);
23812423

2424+
$('#exchange-token').click(
2425+
onExchangeToken
2426+
);
2427+
23822428
// Starts multi-factor enrollment with phone number.
23832429
$('#enroll-mfa-verify-phone-number').click(onStartEnrollWithPhoneMultiFactor);
23842430
// Completes multi-factor enrollment with supplied SMS code.

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('api/authentication/exchange_token', () => {
3737
let regionalAuth: TestAuth;
3838
const request = {
3939
parent: 'test-parent',
40-
token: 'custom-token'
40+
// eslint-disable-next-line camelcase
41+
id_token: 'custom-token'
4142
};
4243

4344
beforeEach(async () => {
@@ -52,6 +53,7 @@ describe('api/authentication/exchange_token', () => {
5253
const mock = mockRegionalEndpointWithParent(
5354
RegionalEndpoint.EXCHANGE_TOKEN,
5455
'test-parent',
56+
'test-api-key',
5557
{ accessToken: 'outbound-token', expiresIn: '1000' }
5658
);
5759

@@ -60,7 +62,8 @@ describe('api/authentication/exchange_token', () => {
6062
expect(response.expiresIn).equal('1000');
6163
expect(mock.calls[0].request).to.eql({
6264
parent: 'test-parent',
63-
token: 'custom-token'
65+
// eslint-disable-next-line camelcase
66+
id_token: 'custom-token'
6467
});
6568
expect(mock.calls[0].method).to.eq('POST');
6669
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
@@ -79,6 +82,7 @@ describe('api/authentication/exchange_token', () => {
7982
const mock = mockRegionalEndpointWithParent(
8083
RegionalEndpoint.EXCHANGE_TOKEN,
8184
'test-parent',
85+
'test-api-key',
8286
{
8387
error: {
8488
code: 400,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Auth } from '../../model/public_types';
2323

2424
export interface ExchangeTokenRequest {
2525
parent: string;
26-
token: string;
26+
id_token: string;
2727
}
2828

2929
export interface ExchangeTokenResponse {

packages/auth/src/api/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ describe('api/_performRegionalApiRequest', () => {
652652
const mock = mockRegionalEndpointWithParent(
653653
RegionalEndpoint.EXCHANGE_TOKEN,
654654
'test-parent',
655+
'test-api-key',
655656
serverResponse
656657
);
657658
const response = await _performRegionalApiRequest<
@@ -689,6 +690,7 @@ describe('api/_performRegionalApiRequest', () => {
689690
const mock = mockRegionalEndpointWithParent(
690691
RegionalEndpoint.EXCHANGE_TOKEN,
691692
'test-parent',
693+
'test-api-key',
692694
serverResponse
693695
);
694696
await _performRegionalApiRequest<typeof request, typeof serverResponse>(

packages/auth/src/api/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,12 @@ async function performApiRequest<T, V>(
168168
}
169169
}
170170

171-
let queryParamString: string;
172-
if (isRegionalAuthInitialized(auth)) {
173-
queryParamString = querystring({
174-
...params
175-
}).slice(1);
176-
} else {
177-
queryParamString = querystring({
171+
const queryParamString = querystring({
178172
key: auth.config.apiKey,
179173
...params
180174
}).slice(1);
181-
}
175+
console.log("here");
176+
console.log(queryParamString);
182177

183178
const headers = await (auth as AuthInternal)._getAdditionalHeaders();
184179
headers[HttpHeader.CONTENT_TYPE] = 'application/json';

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 {

packages/auth/src/core/strategies/exchange_token.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('core/strategies/exchangeToken', () => {
5252
const mock = mockRegionalEndpointWithParent(
5353
RegionalEndpoint.EXCHANGE_TOKEN,
5454
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
55+
'test-api-key',
5556
{ accessToken: 'outbound-token', expiresIn: 10 }
5657
);
5758

@@ -64,7 +65,8 @@ describe('core/strategies/exchangeToken', () => {
6465
expect(mock.calls[0].request).to.eql({
6566
parent:
6667
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
67-
token: 'custom-token'
68+
// eslint-disable-next-line camelcase
69+
id_token: 'custom-token'
6870
});
6971
expect(mock.calls[0].method).to.eq('POST');
7072
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
@@ -87,6 +89,7 @@ describe('core/strategies/exchangeToken', () => {
8789
const mock = mockRegionalEndpointWithParent(
8890
RegionalEndpoint.EXCHANGE_TOKEN,
8991
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
92+
'test-api-key',
9093
{
9194
error: {
9295
code: 400,
@@ -107,7 +110,8 @@ describe('core/strategies/exchangeToken', () => {
107110
expect(mock.calls[0].request).to.eql({
108111
parent:
109112
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
110-
token: 'custom-token'
113+
// eslint-disable-next-line camelcase
114+
id_token: 'custom-token'
111115
});
112116
expect(mock.calls[0].method).to.eq('POST');
113117
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(

packages/auth/src/core/strategies/exhange_token.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export async function exchangeToken(
5252
const authInternal = _castAuth(auth);
5353
const token = await getToken(authInternal, {
5454
parent: buildParent(auth, idpConfigId),
55-
token: customToken
55+
// eslint-disable-next-line camelcase
56+
id_token: customToken
5657
});
5758
if (token) {
5859
await authInternal._updateFirebaseToken({

packages/auth/test/helpers/api/helper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ export function mockEndpointWithParams(
5959
export function mockRegionalEndpointWithParent(
6060
endpoint: RegionalEndpoint,
6161
parent: string,
62+
key: string,
6263
response: object,
6364
status = 200
6465
): Route {
65-
const url = `${TEST_SCHEME}://${TEST_HOST}${parent}${endpoint}`;
66-
console.log('here ', url);
66+
let url = `${TEST_SCHEME}://${TEST_HOST}${parent}${endpoint}`;
67+
url += "?key=";
68+
url += key;
6769
return mock(url, response, status);
6870
}

0 commit comments

Comments
 (0)