Skip to content

Commit ec639cb

Browse files
authored
Merge pull request #541 from ForgeRock/changeset-release/master
Release PR
2 parents f890af3 + fd3493c commit ec639cb

File tree

305 files changed

+1957
-501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+1957
-501
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/DS_Store
44
**/*.DS_Store
55
.pnpm-store/*
6+
67
# Generated code
78
tmp/
89
e2e/**/dist
@@ -30,9 +31,10 @@ packages/javascript-sdk/lib/
3031
.swc
3132
.vite
3233
.env.serve.development
34+
package-lock.json
3335

3436
# Certificates
35-
# *.pem
37+
*.pem
3638

3739
# IDEs
3840
.vscode
@@ -83,4 +85,4 @@ outputs/*
8385

8486
e2e/mock-api-v2/html/*
8587

86-
vitest.config.*.timestamp*
88+
vitest.config.*.timestamp*

e2e/autoscript-apps/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
<a href="./src/authn-basic/index.html">AuthN: Basic</a><br />
2727
<a href="./src/authn-basic-self-service/">AuthN: Self Service</a><br />
2828
<a href="./src/authn-central-login/index.html">AuthN: Central Login</a><br />
29+
<a href="./src/authn-central-login-no-iframe/index.html">AuthN: Central Login, no iframe</a
30+
><br />
2931
<a href="./src/authn-central-logout/index.html">AuthN: Central Logout Ping</a><br />
32+
<a href="./src/authn-central-logout-wellknown/index.html"
33+
>AuthN: Central Logout with Wellknown</a
34+
><br />
3035
<a href="./src/authn-device-profile/index.html">AuthN: Device Profile</a><br />
3136
<a href="./src/authn-protect/index.html">AuthN: Ping Protect</a><br />
3237
<a href="./src/authn-email-suspend/index.html">AuthN: Email Suspend</a><br />
3338
<a href="./src/authn-recaptcha-enterprise/index.html">AuthN: Recaptcha Enterprise</a><br />
3439
<a href="./src/authn-no-session/index.html">AuthN: No Session</a><br />
3540
<a href="./src/authn-oauth/index.html">AuthN: OAuth</a><br />
36-
<a href="./src/authn-wellknown/index.html">AuthN: WellKnown</a><br />
3741
<a href="./src/authn-platform/index.html">AuthN: Platform Login</a><br />
3842
<a href="./src/authn-second-factor/index.html">AuthN: Second Factor</a><br />
3943
<a href="./src/authn-saml/index.html">AuthN: SAML</a><br />

e2e/autoscript-apps/src/authn-basic-self-service/autoscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* autoscript.ts
55
*
6-
* Copyright (c) 2020 ForgeRock. All rights reserved.
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
77
* This software may be modified and distributed under the terms
88
* of the MIT license. See the LICENSE file for details.
99
*/

e2e/autoscript-apps/src/authn-basic/autoscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* autoscript.ts
55
*
6-
* Copyright (c) 2020 ForgeRock. All rights reserved.
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
77
* This software may be modified and distributed under the terms
88
* of the MIT license. See the LICENSE file for details.
99
*/
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* @forgerock/javascript-sdk
3+
*
4+
* autoscript.ts
5+
*
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
7+
* This software may be modified and distributed under the terms
8+
* of the MIT license. See the LICENSE file for details.
9+
*/
10+
// @ts-nocheck
11+
import * as forgerock from '@forgerock/javascript-sdk';
12+
import { delay as rxDelay, map, mergeMap } from 'rxjs/operators';
13+
import { from } from 'rxjs';
14+
15+
function autoscript() {
16+
const delay = 0;
17+
18+
const url = new URL(window.location.href);
19+
const amUrl = url.searchParams.get('amUrl') || 'http://localhost:9443/am';
20+
const preAuthenticated = url.searchParams.get('preAuthenticated') || 'false';
21+
const code = url.searchParams.get('code') || '';
22+
const clientId = url.searchParams.get('clientId');
23+
const client_id = url.searchParams.get('client_id');
24+
const error = url.searchParams.get('error_description') || false;
25+
const realmPath = url.searchParams.get('realmPath') || 'root';
26+
const scope = url.searchParams.get('scope') || 'openid profile me.read';
27+
const state = url.searchParams.get('state') || '';
28+
const acr_values = url.searchParams.get('acr') || 'skipBackgroundRequest';
29+
// in central login we use an auth query param for the return of our mock 401 request
30+
// this is to prevent the evaluation of the page before we have technically authenticated
31+
const auth = url.searchParams.get('auth') || false;
32+
33+
let tokenStore = url.searchParams.get('tokenStore') || 'localStorage';
34+
35+
// Support full redirects by setting storage, rather than rely purely on URL
36+
if (!localStorage.getItem('tokenStore')) {
37+
localStorage.setItem('tokenStore', tokenStore);
38+
} else {
39+
tokenStore = localStorage.getItem('tokenStore');
40+
}
41+
42+
console.log('Configure the SDK');
43+
forgerock.Config.set({
44+
clientId: clientId || client_id || 'CentralLoginOAuthClient',
45+
realmPath,
46+
redirectUri: `${url.origin}/src/${
47+
preAuthenticated === 'false' ? 'authn-central-login' : '_callback'
48+
}/`,
49+
scope,
50+
serverConfig: {
51+
baseUrl: amUrl,
52+
},
53+
tokenStore,
54+
});
55+
56+
if (!code && !state) {
57+
try {
58+
forgerock.SessionManager.logout();
59+
} catch (err) {
60+
// Do nothing
61+
}
62+
}
63+
64+
console.log('Initiate first step with `undefined`');
65+
66+
// Wrapping in setTimeout to give the test time to bind listener to console.log
67+
setTimeout(() => {
68+
from([1])
69+
.pipe(
70+
map(() => {
71+
if (preAuthenticated === 'true') {
72+
console.log('Set mock cookie to represent existing session');
73+
document.cookie = 'iPlanetDirectoryPro=abcd1234; domain=localhost; path=/';
74+
if (code && state) {
75+
window.sessionStorage.setItem(
76+
`FR-SDK-${clientId}`,
77+
JSON.stringify({ responseType: 'code', state, verifier: '1234' }),
78+
);
79+
}
80+
}
81+
return;
82+
}),
83+
rxDelay(delay),
84+
mergeMap((step) => {
85+
let tokens;
86+
// detect when in iframe, throw as error if so
87+
if (window.self !== window.top) {
88+
throw new Error('Loaded_In_Iframe');
89+
} else if (code && state) {
90+
tokens = forgerock.TokenManager.getTokens({
91+
query: { code, state, acr_values },
92+
});
93+
} else {
94+
tokens = forgerock.TokenManager.getTokens({
95+
skipBackgroundRequest: true,
96+
login: 'redirect',
97+
query: { acr_values },
98+
});
99+
}
100+
return tokens;
101+
}),
102+
map((tokens) => {
103+
if (tokens.accessToken) {
104+
console.log('OAuth authorization successful');
105+
document.body.innerHTML = '<p class="Logged_In">Login successful</p>';
106+
} else {
107+
throw new Error('Session_Error');
108+
}
109+
}),
110+
rxDelay(delay),
111+
mergeMap(() => {
112+
console.log('Remove cookie');
113+
document.cookie = '';
114+
console.log('Initiate logout');
115+
return forgerock.FRUser.logout();
116+
}),
117+
)
118+
.subscribe({
119+
error: (err) => {
120+
/*
121+
* We added this because Playwright was too fast for the dom element.
122+
* When we make a request to central login we have to force a 401 page to mimick the real life scenario of the page being requested
123+
* If we do this, we append a query param of auth to make sure we don't complete the flow until we are redirected from that page
124+
* By saying we have !auth query param value, we are essentially mimicking the idea that we are waiting for the central login redirect
125+
* to complete the redirect.
126+
*/
127+
if (!auth) {
128+
return;
129+
}
130+
console.log(`Error: ${err.message}`);
131+
document.body.innerHTML = `<p class="Test_Complete">${err.message}</p>`;
132+
localStorage.clear();
133+
},
134+
complete: () => {
135+
console.log('Test script complete');
136+
document.body.innerHTML = `<p class="Test_Complete">Test script complete</p>`;
137+
history.replaceState(null, null, window.location.origin + window.location.pathname);
138+
localStorage.clear();
139+
},
140+
});
141+
}, 250);
142+
}
143+
144+
autoscript();
145+
export default autoscript;

e2e/autoscript-apps/src/authn-wellknown/index.html renamed to e2e/autoscript-apps/src/authn-central-login-no-iframe/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
</head>
2929

3030
<body>
31-
<!-- script src="/_polyfills/fast-text-encoder.js"></script -->
32-
33-
<script src="autoscript.ts" type="module"></script>
31+
<script type="module" src="./autoscript.ts"></script>
3432
</body>
3533
</html>

e2e/autoscript-apps/src/authn-central-login-wellknown/autoscript.ts

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* autoscript.ts
55
*
6-
* Copyright (c) 2020 ForgeRock. All rights reserved.
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
77
* This software may be modified and distributed under the terms
88
* of the MIT license. See the LICENSE file for details.
99
*/
@@ -16,49 +16,50 @@ async function autoscript() {
1616
const delay = 0;
1717

1818
const url = new URL(window.location.href);
19+
const preAuthenticated = url.searchParams.get('preAuthenticated') || 'false';
1920
const code = url.searchParams.get('code') || '';
20-
const error = url.searchParams.get('error') || '';
21+
const clientId = url.searchParams.get('clientId');
22+
const client_id = url.searchParams.get('client_id');
23+
const error = url.searchParams.get('error_description') || false;
24+
const realmPath = url.searchParams.get('realmPath') || 'root';
25+
const scope = url.searchParams.get('scope') || 'openid profile me.read';
2126
const state = url.searchParams.get('state') || '';
27+
const acr_values = url.searchParams.get('acr') || 'SpecificTree';
2228
// in central login we use an auth query param for the return of our mock 401 request
2329
// this is to prevent the evaluation of the page before we have technically authenticated
2430
const auth = url.searchParams.get('auth') || false;
25-
const acr_values = url.searchParams.get('acr') || 'SpecificTree';
31+
let wellknown =
32+
url.searchParams.get('wellknown') || 'http://localhost:9443/am/.well-known/oidc-configuration';
2633

27-
let clientId = url.searchParams.get('clientId') || 'CentralLoginOAuthClient';
28-
let realmPath = url.searchParams.get('realmPath') || 'root';
29-
// The `revoke` scope is required for PingOne support
30-
let scope = url.searchParams.get('scope') || 'openid profile me.read revoke';
31-
let wellKnownUrl =
32-
url.searchParams.get('wellKnownUrl') ||
33-
'http://localhost:9443/am/.well-known/oidc-configuration';
34+
let tokenStore = url.searchParams.get('tokenStore') || 'localStorage';
3435

35-
console.log('Configure the SDK');
36-
37-
if (wellKnownUrl) {
38-
localStorage.setItem('wellknown', wellKnownUrl);
39-
localStorage.setItem('clientId', clientId);
40-
localStorage.setItem('realmPath', realmPath);
41-
localStorage.setItem('scope', scope);
36+
// Support full redirects by setting storage, rather than rely purely on URL
37+
if (!localStorage.getItem('tokenStore')) {
38+
localStorage.setItem('tokenStore', tokenStore);
4239
} else {
43-
wellKnownUrl = localStorage.getItem('wellknown');
44-
clientId = localStorage.getItem('clientId');
45-
realmPath = localStorage.getItem('realmPath');
46-
scope = localStorage.getItem('scope');
40+
tokenStore = localStorage.getItem('tokenStore');
4741
}
48-
await forgerock.Config.setAsync({
49-
clientId,
42+
43+
console.log('Configure the SDK');
44+
forgerock.Config.setAsync({
45+
clientId: clientId || client_id || 'CentralLoginOAuthClient',
5046
realmPath,
51-
redirectUri: `${url.origin}/src/authn-central-login-wellknown/`,
47+
redirectUri: `${url.origin}/src/${
48+
preAuthenticated === 'false' ? 'authn-central-login' : '_callback'
49+
}/`,
5250
scope,
5351
serverConfig: {
54-
wellknown: wellKnownUrl,
52+
wellknown,
5553
},
54+
tokenStore,
5655
});
5756

58-
try {
59-
forgerock.SessionManager.logout();
60-
} catch (err) {
61-
// Do nothing
57+
if (!code && !state) {
58+
try {
59+
forgerock.SessionManager.logout();
60+
} catch (err) {
61+
// Do nothing
62+
}
6263
}
6364

6465
console.log('Initiate first step with `undefined`');
@@ -67,15 +68,29 @@ async function autoscript() {
6768
setTimeout(() => {
6869
from([1])
6970
.pipe(
70-
mergeMap(() => {
71+
map(() => {
72+
if (preAuthenticated === 'true') {
73+
console.log('Set mock cookie to represent existing session');
74+
document.cookie = 'iPlanetDirectoryPro=abcd1234; domain=localhost; path=/';
75+
if (code && state) {
76+
window.sessionStorage.setItem(
77+
`FR-SDK-authflow-${clientId}`,
78+
JSON.stringify({ responseType: 'code', state, verifier: '1234' }),
79+
);
80+
}
81+
}
82+
return;
83+
}),
84+
rxDelay(delay),
85+
mergeMap((step) => {
7186
let tokens;
72-
// detect when in iframe as to not call `/authorize` needlessly
73-
if (window.self !== window.top) {
87+
if (error) {
88+
// Do nothing
7489
return;
7590
} else if (code && state) {
7691
tokens = forgerock.TokenManager.getTokens({
7792
login: 'redirect',
78-
query: { code, state },
93+
query: { code, state, acr_values },
7994
});
8095
} else {
8196
tokens = forgerock.TokenManager.getTokens({
@@ -98,7 +113,6 @@ async function autoscript() {
98113
console.log('Remove cookie');
99114
document.cookie = '';
100115
console.log('Initiate logout');
101-
// You have to allow specific origins to CORS for OAuth client
102116
return forgerock.FRUser.logout();
103117
}),
104118
)
@@ -116,14 +130,12 @@ async function autoscript() {
116130
}
117131
console.log(`Error: ${err.message}`);
118132
document.body.innerHTML = `<p class="Test_Complete">${err.message}</p>`;
133+
localStorage.clear();
119134
},
120135
complete: () => {
121136
console.log('Test script complete');
122137
document.body.innerHTML = `<p class="Test_Complete">Test script complete</p>`;
123-
localStorage.removeItem('wellknown');
124-
localStorage.removeItem('clientId');
125-
localStorage.removeItem('realmPath');
126-
localStorage.removeItem('scope');
138+
localStorage.clear();
127139
},
128140
});
129141
}, 250);

e2e/autoscript-apps/src/authn-central-login/autoscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* autoscript.ts
55
*
6-
* Copyright (c) 2020 ForgeRock. All rights reserved.
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
77
* This software may be modified and distributed under the terms
88
* of the MIT license. See the LICENSE file for details.
99
*/

0 commit comments

Comments
 (0)