Skip to content

Conversation

Hellebore
Copy link

@Hellebore Hellebore commented May 2, 2025

Jira link

https://tools.hmcts.net/jira/browse/EXUI-3061

Change description

Get isserOverride value from Idam api

Checklist

  • commit messages are meaningful and follow good commit message guidelines
  • README and other documentation has been updated / added (if needed)
  • tests have been updated / new tests has been added (if needed)
  • Does this PR introduce a breaking change

Summary by Sourcery

Modify authentication middleware to dynamically retrieve issuer override value from IDAM API

New Features:

  • Fetch service override value dynamically from IDAM API using client credentials

Enhancements:

  • Update XUI node middleware to support asynchronous token and service details retrieval
  • Implement fallback mechanism for service override configuration

Chores:

  • Refactor application startup to use async initialization

@Hellebore
Copy link
Author

This is a benchmark review for experiment bakeoff.
Run ID: bakeoff/benchmark_2025-05-02T11-38-04_v1-36-0-dirty.

This pull request was cloned from https://github.com/hmcts/rpx-xui-webapp/pull/4438. (Note: the URL is not a link to avoid triggering a notification on the original pull request.)

Experiment configuration
review_config:
  # User configuration for the review
  # - benchmark - use the user config from the benchmark reviews
  # - <value> - use the value directly
  user_review_config:
    enable_ai_review: true
    enable_rule_comments: false

    enable_complexity_comments: benchmark
    enable_security_comments: benchmark
    enable_tests_comments: benchmark
    enable_comment_suggestions: benchmark

    enable_pull_request_summary: benchmark
    enable_review_guide: benchmark

    enable_approvals: false
    base_branches: [base-sha.*]

  ai_review_config:
    # The model responses to use for the experiment
    # - benchmark - use the model responses from the benchmark reviews
    # - llm - call the language model to generate responses
    model_responses:
      comments_model: benchmark
      comment_validation_model: benchmark
      comment_suggestion_model: benchmark
      complexity_model: benchmark
      security_model: benchmark
      tests_model: benchmark
      pull_request_summary_model: benchmark
      review_guide_model: benchmark
      overall_comments_model: benchmark

# The pull request dataset to run the experiment on
pull_request_dataset:
# CodeRabbit
- https://github.com/neerajkumar161/node-coveralls-integration/pull/5
- https://github.com/gunner95/vertx-rest/pull/1
- https://github.com/Altinn/altinn-access-management-frontend/pull/1427
- https://github.com/theMr17/github-notifier/pull/14
- https://github.com/bearycool11/AI_memory_Loops/pull/142

# Greptile
- https://github.com/gumloop/guMCP/pull/119
- https://github.com/autoblocksai/python-sdk/pull/335
- https://github.com/grepdemos/ImageSharp/pull/6
- https://github.com/grepdemos/server/pull/61
- https://github.com/websentry-ai/pipelines/pull/25

# Graphite
- https://github.com/KittyCAD/modeling-app/pull/6648
- https://github.com/KittyCAD/modeling-app/pull/6628
- https://github.com/Varedis-Org/AI-Test-Repo/pull/2
- https://github.com/deeep-network/bedrock/pull/198
- https://github.com/Metta-AI/metta/pull/277

# Copilot
- https://github.com/hmcts/rpx-xui-webapp/pull/4438
- https://github.com/ganchdev/quez/pull/104
- https://github.com/xbcsmith/ymlfxr/pull/13
- https://github.com/tinapayy/B-1N1T/pull/36
- https://github.com/coder/devcontainer-features/pull/6

# Questions to ask to label the review comments
review_comment_labels: []
# - label: correct
#   question: Is this comment correct?

# Benchmark reviews generated by running
#   python -m scripts.experiment benchmark <experiment_name>
benchmark_reviews: []

@Hellebore
Copy link
Author

Reviewer's Guide

The pull request updates the authentication middleware to dynamically fetch the issuerOverride value from the IDAM /api/v2/services/{clientId} endpoint. This is achieved by introducing asynchronous operations within getXuiNodeMiddleware to first obtain an access token using the client credentials grant type and then using that token to call the service details endpoint. Error handling is included to fall back to the configuration value if the API call fails. The application startup sequence in application.ts has been modified to accommodate the asynchronous initialization of this middleware.

File-Level Changes

Change Details Files
Dynamically fetch issuerOverride from IDAM API
  • Added functions getToken and getClientServiceDetails to interact with IDAM API.
  • Implemented client credentials flow to obtain an access token.
  • Called the /api/v2/services/{clientId} endpoint to get service details.
  • Extracted issuerOverride from the API response.
  • Added error handling with fallback to configuration value (SERVICES_IDAM_SERVICE_OVERRIDE).
api/auth/index.ts
Made authentication middleware initialization asynchronous
  • Changed getXuiNodeMiddleware to an async function.
  • Used await when calling getClientServiceDetails within getXuiNodeMiddleware.
  • Wrapped application setup in application.ts in an async IIFE.
  • Used await when calling getXuiNodeMiddleware before applying it in application.ts.
api/auth/index.ts
api/application.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Author

@Hellebore Hellebore left a comment

Choose a reason for hiding this comment

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

Hey @Hellebore - I've reviewed your changes - here's some feedback:

  • Fetching the issuerOverride from the API during startup might delay application readiness; consider the impact of potential IDAM API latency.
  • Ensure that failures to fetch the issuerOverride during startup are adequately monitored, as the current fallback might mask underlying issues.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

LangSmith trace

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

xuiNode.on(AUTH.EVENT.AUTHENTICATE_FAILURE, failureCallback);

export const getXuiNodeMiddleware = () => {
export const getXuiNodeMiddleware = async () => {
Copy link
Author

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.

options.serviceOverride = await getClientServiceDetails();
const type = showFeature(FEATURE_OIDC_ENABLED) ? 'oidc' : 'oauth2';
nodeLibOptions.auth[type] = options;
logger._logger.info('Setting XuiNodeLib options');
Copy link
Author

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants