Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept showing the frontend using keycloak on an arbitrary domain #2385

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions src/common/api/Keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ let keycloak = null
let isInitialized = false
let initPromise = null

const keycloakConfig = {
"realm": "hmda2",
"url": "https://{{domain}}}/auth",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you try replacing line 9 with the following to make it dynamic?
"url": `https://${window.location.hostname}/auth`,

Copy link
Contributor

Choose a reason for hiding this comment

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

To account for local testing, please use the following:

let keycloakRedirect = null
if (hostname == 'localhost') {
  keycloakRedirect = 'ffiec.cfpb.gov'
} else {
  keycloakRedirect = hostname
}

const keycloakConfig = {
  "realm": "hmda2",
  "url": `https://${keycloakRedirect}/auth`,
  "clientId": "hmda2-api",
  "public-client": true,
  "use-resource-role-mappings": true,
  "confidential-port": 0,
  "ssl-required": "all"
}```

"clientId": "hmda2-api",
"public-client": true,
"use-resource-role-mappings": true,
"confidential-port": 0,
"ssl-required": "all"
}

export const setKeycloak = (cloak) => {
keycloak = cloak
return keycloak
Expand All @@ -28,12 +38,12 @@ export const initKeycloak = (overrides) => {
} else if (import.meta.env.MODE === 'development') {
keycloak = new Keycloak('/local_keycloak.json')
} else {
keycloak = new Keycloak('/keycloak.json')
keycloak = new Keycloak(keycloakConfig)

Choose a reason for hiding this comment

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

Would it be any easier to manage/revert the keycloak config as a ConfigMap?

}
}

initPromise = keycloak
.init({ pkceMethod: 'S256' })
.init({ pkceMethod: 'S256', checkLoginIframe: false })
.then((authenticated) => {
console.log('Keycloak initialized, authenticated:', authenticated)
isInitialized = true
Expand Down