Skip to content

migration: openid-client and jose migration#785

Open
aks96 wants to merge 6 commits intomasterfrom
migration/openid-clientv6
Open

migration: openid-client and jose migration#785
aks96 wants to merge 6 commits intomasterfrom
migration/openid-clientv6

Conversation

@aks96
Copy link
Contributor

@aks96 aks96 commented Feb 9, 2026

Description

This PR upgrades the core dependencies openid-client (v4.9.1 → v6.1.3) and jose (v2.0.7 → v6.1.3) to their latest major versions, bringing improved security, performance, and standards compliance.

All Tests Passing: 266/266 tests (100%) - 256 unit tests + 10 end-to-end tests
Zero Breaking Changes to public API
Node.js 20+ Required

Testing

Tested all the examples from example folder.

@aks96 aks96 requested a review from a team as a code owner February 9, 2026 12:39
@@ -0,0 +1,190 @@
# V3 Migration Guide

Choose a reason for hiding this comment

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

Just a thought.
Since consumer facing api has no breaking changes, do we need to mention that and it's usage examples here, in detail.
IMO, if consumer comes to read the migration guide, consumer has to go through a lot of detail to be assured that there are no breaking changes.
Would it not suffice to just mention the breaking changes and what consumer are required to follow.
@aks96 What do you think!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we are making sure user understand what changes has been done, regarding breaking changes it just user has to update node, openid-client and jose version.


// Build a Request object for openid-client v6
const protocol = req.protocol;
const host = req.get('host'); // Use req.get('host') to include port
Copy link
Member

Choose a reason for hiding this comment

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

This will not work in any deployment behind a TLS terminating reverse proxy. It'll give back the internal hostname and port which has no relation to the URL the browser is hitting. This URL is used by openid-client to populate the redirect_uri access token request parameter, thus causing a mismatch.

Copy link
Member

Choose a reason for hiding this comment

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

Using req getters is necessary to account for the express application's trust proxy settings, https://expressjs.com/en/guide/behind-proxies.html

Copy link
Member

@panva panva Feb 11, 2026

Choose a reason for hiding this comment

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

Unfortunately there's a bug in express@4 where req.host is an alias to req.hostname and thus not containing ports. express@5 req.host works as expected.

To work around this use the following (taken from https://github.com/panva/openid-client/blob/b77d87c1e2f5fef6fab501de615fb83a74a0251f/src/passport.ts#L211C1-L232)

function host(req: express.Request): string | undefined {
  try {
    const trust = req.app.get('trust proxy fn')
    let val = req.get('x-forwarded-host')

    if (!val || !trust(req.socket.remoteAddress, 0)) {
      val = req.get('host')
    } else if (val.indexOf(',') !== -1) {
      val = val.substring(0, val.indexOf(',')).trimRight()
    }

    return val || undefined
  } catch {
    return req.host
  }
}

// Build a Request object for openid-client v6
const protocol = req.protocol;
const host = req.get('host'); // Use req.get('host') to include port
const currentUrl = new URL(`${protocol}://${host}${req.originalUrl}`);
Copy link
Member

Choose a reason for hiding this comment

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

To account for mounted app scenarios

Suggested change
const currentUrl = new URL(`${protocol}://${host}${req.originalUrl}`);
const currentUrl = new URL(`${protocol}://${host}${req.originalUrl ?? req.url}`);

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.

3 participants

Comments