forked from hmcts/rpx-xui-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
EXUI-3601: Call Idam api to get issue override value #1
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
Open
Hellebore
wants to merge
2
commits into
base-sha/6ead1c32c488fc29e0817d010847345ee20a3c2b
Choose a base branch
from
head-sha/1623f020817bd828080ad38645ed8241a3451e36/2025-05-02T11-45-18/6fb561
base: base-sha/6ead1c32c488fc29e0817d010847345ee20a3c2b
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ import { | |
import { client, trackTrace } from '../lib/appInsights'; | ||
import * as log4jui from '../lib/log4jui'; | ||
import { EnhancedRequest } from '../lib/models'; | ||
import axios from 'axios'; | ||
import qs = require('qs'); | ||
|
||
const logger = log4jui.getLogger('auth'); | ||
|
||
|
@@ -72,7 +74,7 @@ export const failureCallback = (req: EnhancedRequest, res: Response) => { | |
xuiNode.on(AUTH.EVENT.AUTHENTICATE_SUCCESS, successCallback); | ||
xuiNode.on(AUTH.EVENT.AUTHENTICATE_FAILURE, failureCallback); | ||
|
||
export const getXuiNodeMiddleware = () => { | ||
export const getXuiNodeMiddleware = async () => { | ||
const idamWebUrl = getConfigValue(SERVICES_IDAM_LOGIN_URL); | ||
const authorizationUrl = `${idamWebUrl}/login`; | ||
const secret = getConfigValue(IDAM_SECRET); | ||
|
@@ -83,6 +85,7 @@ export const getXuiNodeMiddleware = () => { | |
const tokenUrl = `${getConfigValue(SERVICES_IDAM_API_URL)}/oauth2/token`; | ||
const userName = getConfigValue(SYSTEM_USER_NAME); | ||
const password = getConfigValue(SYSTEM_USER_PASSWORD); | ||
const clientServiceDetailsUrl = `${getConfigValue(SERVICES_IDAM_API_URL)}/api/v2/services/${idamClient}`; | ||
|
||
const routeCredential = { | ||
password, | ||
|
@@ -169,6 +172,43 @@ export const getXuiNodeMiddleware = () => { | |
session: showFeature(FEATURE_REDIS_ENABLED) ? redisStoreOptions : fileStoreOptions | ||
}; | ||
|
||
const getToken = async () => { | ||
const data = qs.stringify({ | ||
grant_type: 'client_credentials', | ||
client_id: idamClient, | ||
client_secret: secret, | ||
scope: 'profile roles view-service-provider' | ||
}); | ||
try { | ||
const response = await axios.post(tokenUrl, data, { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
}); | ||
return response.data.access_token; | ||
} catch (error) { | ||
logger.error('Error fetching token:', error); | ||
} | ||
}; | ||
|
||
const getClientServiceDetails = async () => { | ||
try { | ||
const accessToken = await getToken(); | ||
if (!accessToken) { | ||
throw new Error('Failed to get access token'); | ||
} | ||
const response = await axios.get(clientServiceDetailsUrl, { headers: { | ||
'Authorization': `Bearer ${accessToken}` | ||
} }); | ||
logger.info('Successfully retrieved service override from API'); | ||
return response.data.oauth2.issuerOverride; | ||
} catch (error) { | ||
logger.error('Error retrieving service override from API, falling back to config value', error); | ||
return getConfigValue(SERVICES_IDAM_SERVICE_OVERRIDE); | ||
} | ||
}; | ||
|
||
options.serviceOverride = await getClientServiceDetails(); | ||
const type = showFeature(FEATURE_OIDC_ENABLED) ? 'oidc' : 'oauth2'; | ||
nodeLibOptions.auth[type] = options; | ||
logger._logger.info('Setting XuiNodeLib options'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Potential inconsistency using logger._logger.info. Using logger._logger bypasses the logging abstraction and any middleware hooks. Use logger.info instead unless you specifically need direct access to _logger. |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (bug_risk): Async change in getXuiNodeMiddleware requires careful consideration.
Double-check that every consumer awaits getXuiNodeMiddleware’s promise. You’ve updated api/application.ts, but review other usages to ensure none remain unhandled.