Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import React, { useContext } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { Link, useLocation, useSearchParams } from 'react-router-dom';

import AccountIcon from '../icons/account-icon';
import ForgeRockIcon from '../icons/forgerock-icon';
Expand All @@ -34,6 +34,7 @@ export default function Header() {
const [auth] = useContext(AuthContext);
const theme = useContext(ThemeContext);
const location = useLocation();
const [searchParams] = useSearchParams();
const { openModal } = useLoginWidget();

let TodosItem;
Expand Down Expand Up @@ -112,7 +113,7 @@ export default function Header() {
className={`cstm_login-link py-2 px-3 mx-1 ${
theme.mode === 'dark' ? 'cstm_login-link_dark' : ''
}`}
onClick={openModal}
onClick={() => openModal(searchParams.get('journey'))}
href="#"
>
Sign In
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export function useLoginWidget() {
};
}, []);

function openModal() {
function openModal(journeyName) {
const authSetters = setAuthRef.current;
authSetters?.setError?.('');
journeyEvents.start();
journeyEvents.start(journeyName ? { journey: journeyName } : undefined);
componentEvents.open();
}

Expand Down
6 changes: 6 additions & 0 deletions javascript/reactjs-todo-login-widget/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ configuration().set({
tree: `${journeyParam || JOURNEY_LOGIN}`,
tokenStore: 'localStorage',
},
// Required by Journey Client v2: OIDC discovery URL for the realm
journeyClient: {
serverConfig: {
wellknown: `${SERVER_URL}oauth2/realms/root/realms/${REALM_PATH}/.well-known/openid-configuration`,
},
},
Comment on lines +70 to +75
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify realm/env formats and existing wellknown construction patterns

set -euo pipefail

echo "== REALM_PATH usage in login-widget sample =="
rg -n -C2 'REALM_PATH|realmPath|wellknown|oauth2/realms/root' javascript/reactjs-todo-login-widget/client

echo
echo "== Any sample .env templates that document REALM_PATH format =="
fd -HI '.env*' javascript | sed 's#^`#-` #'
rg -n -C1 'REALM_PATH|SERVER_URL' $(fd -HI '.env*' javascript) || true

echo
echo "== Compare journeyClient.wellknown patterns across JS samples =="
rg -n -C2 'journeyClient|wellknown|oauth2/realms/root' javascript

Repository: ForgeRock/sdk-sample-apps

Length of output: 22846


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== login-widget client README/.env.example for REALM_PATH format =="
sed -n '1,120p' javascript/reactjs-todo-login-widget/client/README.md
echo "----"
sed -n '1,120p' javascript/reactjs-todo-login-widget/.env.example
echo "----"
sed -n '1,120p' javascript/reactjs-todo-login-widget/client/constants.js

echo
echo "== todo-api middleware: how it builds realm paths for non-root =="
sed -n '1,120p' javascript/todo-api/src/app/middleware.js

echo
echo "== reactjs-todo-journey: how it sources wellknown URL =="
rg -n "WELLKNOWN|wellknown" javascript/reactjs-todo-journey/client -S
echo "----"
rg -n "WELLKNOWN|wellknown" javascript/reactjs-todo-oidc/client -S
echo "----"
ls -la javascript/reactjs-todo-journey/client/constants.js javascript/reactjs-todo-oidc/client/constants.js 2>/dev/null || true
sed -n '1,120p' javascript/reactjs-todo-journey/client/constants.js 2>/dev/null || true
sed -n '1,120p' javascript/reactjs-todo-oidc/client/constants.js 2>/dev/null || true

Repository: ForgeRock/sdk-sample-apps

Length of output: 12418


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== login-widget client index.js around realmPath docs and wellknown template =="
sed -n '1,120p' javascript/reactjs-todo-login-widget/client/index.js | nl -ba | sed -n '35,95p'

echo
echo "== Search repo for journey discovery pattern '/oauth2/realms/root/realms/' =="
rg -n "oauth2/realms/root/realms/" javascript | head -n 50

echo
echo "== Search repo for 'wellknown: .*openid-configuration' constructions =="
rg -n "wellknown:.*openid-configuration|openid-configuration" javascript/reactjs-todo-login-widget javascript/reactjs-todo-journey javascript/reactjs-todo-oidc javascript/todo-api | head -n 80

Repository: ForgeRock/sdk-sample-apps

Length of output: 210


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== login-widget client index.js around realmPath docs and wellknown template =="
sed -n '1,120p' javascript/reactjs-todo-login-widget/client/index.js | cat -n | sed -n '35,95p'

echo
echo "== Search repo for journey discovery pattern '/oauth2/realms/root/realms/' =="
rg -n "oauth2/realms/root/realms/" javascript | head -n 50

echo
echo "== Search repo for 'wellknown: .*openid-configuration' constructions =="
rg -n "wellknown:.*openid-configuration|openid-configuration" javascript/reactjs-todo-login-widget javascript/reactjs-todo-journey javascript/reactjs-todo-oidc javascript/todo-api | head -n 120

Repository: ForgeRock/sdk-sample-apps

Length of output: 4238


Fix OIDC discovery wellknown URL for REALM_PATH="root" in login-widget

javascript/reactjs-todo-login-widget/client/index.js line 73 always builds ${SERVER_URL}oauth2/realms/root/realms/${REALM_PATH}/.well-known/openid-configuration. With REALM_PATH="root" (documented as a supported value), this produces /oauth2/realms/root/realms/root/..., which is inconsistent with the repo’s AIC root handling elsewhere (e.g., todo-api/src/app/middleware.js omits the /realms/${REALM_PATH} segment when the realm is root).

Suggested fix
+const normalizedRealmPath = (REALM_PATH || '').replace(/^\/+|\/+$/g, '');
+const realmSuffix =
+  normalizedRealmPath && normalizedRealmPath !== 'root'
+    ? `/realms/${normalizedRealmPath.split('/').join('/realms/')}`
+    : '';
+const normalizedServerUrl = SERVER_URL.endsWith('/') ? SERVER_URL : `${SERVER_URL}/`;
+
 configuration().set({
   forgerock: {
@@
   journeyClient: {
     serverConfig: {
-      wellknown: `${SERVER_URL}oauth2/realms/root/realms/${REALM_PATH}/.well-known/openid-configuration`,
+      wellknown: `${normalizedServerUrl}oauth2/realms/root${realmSuffix}/.well-known/openid-configuration`,
     },
   },
 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@javascript/reactjs-todo-login-widget/client/index.js` around lines 70 - 75,
The wellknown OIDC discovery URL in journeyClient.serverConfig currently always
appends "/realms/${REALM_PATH}", producing a duplicated segment when REALM_PATH
=== "root"; update the URL construction in journeyClient.serverConfig.wellknown
so that if REALM_PATH is "root" you omit the "/realms/${REALM_PATH}" segment
(i.e., use `${SERVER_URL}oauth2/.well-known/openid-configuration` for root,
otherwise
`${SERVER_URL}oauth2/realms/${REALM_PATH}/.well-known/openid-configuration`),
locate this change at the journeyClient.serverConfig.wellknown assignment in
client/index.js and implement the conditional string construction accordingly.

});

/**
Expand Down
Loading