-
Notifications
You must be signed in to change notification settings - Fork 155
migration: openid-client and jose migration #785
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
aks96
wants to merge
6
commits into
master
Choose a base branch
from
migration/openid-clientv6
base: master
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
6 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
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 |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| # V3 Migration Guide | ||
|
|
||
| `v3.x` upgrades the underlying OpenID Connect and JWT dependencies (`openid-client` v4 → v6, `jose` v2 → v6) to their latest major versions, bringing improved security, performance, and standards compliance. | ||
|
|
||
| **Important:** While this is a major version bump for the library, **there are ZERO breaking changes to the public API**. Your application code does not need to change. | ||
|
|
||
| --- | ||
|
|
||
| **Public API:** No breaking changes - all configuration, middleware, and context APIs work exactly the same | ||
| **Node.js Version:** Now requires `^20.19.0 || ^22.12.0 || >= 23.0.0` (previously Node.js 14+) | ||
| **Module Support:** Works with BOTH CommonJS and ESM apps | ||
|
|
||
| --- | ||
|
|
||
| ## Breaking Changes | ||
|
|
||
| ### Node.js Version Requirement | ||
|
|
||
| **The only breaking change is the specific Node.js version requirement.** | ||
|
|
||
| | Version | Minimum Node.js | Status | | ||
| | ------- | --------------------------------------- | ------- | | ||
| | v2.x | Node.js 14+ | Old | | ||
| | v3.x | `^20.19.0 \|\| ^22.12.0 \|\| >= 23.0.0` | **New** | | ||
|
|
||
| #### Why These Specific Versions? | ||
|
|
||
| The updated dependencies (`openid-client` v6 and `jose` v6) are **ESM-only packages**. | ||
|
|
||
| Node.js added `require(ESM)` support in: | ||
|
|
||
| - **v20.19.0** (backported to v20.x LTS) | ||
| - **v22.12.0** (backported to v22.x LTS) | ||
| - **v23.0.0+** (included by default) | ||
|
|
||
| There is **no workaround** - you must upgrade to a supported Node.js version. | ||
|
|
||
| #### Module System Support | ||
|
|
||
| **Works with BOTH CommonJS and ESM apps** - same Node.js requirements for both: | ||
|
|
||
| ```javascript | ||
| // CommonJS - Works on supported Node.js versions | ||
| const { auth } = require('express-openid-connect'); | ||
|
|
||
| // ESM - Works on supported Node.js versions | ||
| import { auth } from 'express-openid-connect'; | ||
| ``` | ||
|
|
||
| **Note:** ESM apps need `"type": "module"` in `package.json` but have identical Node.js version requirements as CommonJS apps. | ||
|
|
||
| ### Configuration | ||
|
|
||
| All configuration options work exactly as before. No changes needed. | ||
|
|
||
| ```js | ||
| const { auth } = require('express-openid-connect'); | ||
|
|
||
| // This configuration works EXACTLY the same in v3.x | ||
| app.use( | ||
| auth({ | ||
| authRequired: false, | ||
| auth0Logout: true, | ||
| baseURL: 'https://example.com', | ||
| clientID: 'YOUR_CLIENT_ID', | ||
| issuerBaseURL: 'https://YOUR_DOMAIN', | ||
| secret: 'LONG_RANDOM_STRING', | ||
|
|
||
| // All these options still work | ||
| idpLogout: true, | ||
| idTokenSigningAlg: 'RS256', | ||
| clientAuthMethod: 'client_secret_post', | ||
| pushedAuthorizationRequests: true, | ||
| // ... etc | ||
| }), | ||
| ); | ||
| ``` | ||
|
|
||
| ### Middleware | ||
|
|
||
| All middleware functions work identically. | ||
|
|
||
| ```js | ||
| const { auth, requiresAuth } = require('express-openid-connect'); | ||
|
|
||
| // All these work EXACTLY the same | ||
| app.use(auth(config)); | ||
| app.get('/admin', requiresAuth(), (req, res) => { | ||
| res.send('Admin page'); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Request Context (req.oidc) | ||
|
|
||
| The entire `req.oidc` API remains unchanged. | ||
|
|
||
| ```js | ||
| // Before (v2.x) | ||
| app.get('/profile', async (req, res) => { | ||
| const user = req.oidc.user; | ||
| const claims = req.oidc.idTokenClaims; | ||
| const isAuthenticated = req.oidc.isAuthenticated(); | ||
| const idToken = req.oidc.idToken; | ||
| const accessToken = req.oidc.accessToken; | ||
| const refreshToken = req.oidc.refreshToken; | ||
| const userInfo = await req.oidc.fetchUserInfo(); | ||
|
|
||
| res.oidc.login({}); | ||
| res.oidc.logout({}); | ||
| }); | ||
|
|
||
| // After (v3.x) - SAME | ||
| app.get('/profile', async (req, res) => { | ||
| const user = req.oidc.user; | ||
| const claims = req.oidc.idTokenClaims; | ||
| const isAuthenticated = req.oidc.isAuthenticated(); | ||
| const idToken = req.oidc.idToken; | ||
| const accessToken = req.oidc.accessToken; | ||
| const refreshToken = req.oidc.refreshToken; | ||
| const userInfo = await req.oidc.fetchUserInfo(); | ||
|
|
||
| res.oidc.login({}); | ||
| res.oidc.logout({}); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Routes | ||
|
|
||
| Custom route configuration remains unchanged. | ||
|
|
||
| ```js | ||
| // This works the same in v3.x | ||
| app.use( | ||
| auth({ | ||
| routes: { | ||
| login: '/custom/login', | ||
| logout: '/custom/logout', | ||
| callback: '/custom/callback', | ||
| postLogoutRedirect: '/custom/post-logout', | ||
| }, | ||
| }), | ||
| ); | ||
| ``` | ||
|
|
||
| ### Session Handling | ||
|
|
||
| Session configuration, custom stores, and lifecycle hooks all work the same. | ||
|
|
||
| ```js | ||
| // Session configuration - UNCHANGED | ||
| app.use( | ||
| auth({ | ||
| session: { | ||
| rolling: true, | ||
| rollingDuration: 86400, | ||
| absoluteDuration: 86400 * 7, | ||
| store: customStore, // Custom session stores still work | ||
| }, | ||
| }), | ||
| ); | ||
| ``` | ||
|
|
||
| ### Authentication Methods | ||
|
|
||
| All client authentication methods continue to work: | ||
|
|
||
| ```js | ||
| // All these still work in v3.x | ||
| const config = { | ||
| clientAuthMethod: 'client_secret_basic', | ||
| clientAuthMethod: 'client_secret_post', | ||
| clientAuthMethod: 'client_secret_jwt', | ||
| clientAuthMethod: 'private_key_jwt', | ||
| clientAuthMethod: 'none', | ||
| }; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ```bash | ||
| node --version | ||
| ``` | ||
|
|
||
| **Required:** `v20.19.0+`, `v22.12.0+`, or `v23.0.0+` | ||
|
|
||
| If your version is older: | ||
|
|
||
| - **v20.0.0 - v20.18.0** → Upgrade to v20.19.0+ | ||
| - **v22.0.0 - v22.11.0** → Upgrade to v22.12.0+ | ||
| - **v18.x or earlier** → Upgrade to v22.12.0+ (recommended LTS) | ||
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 |
|---|---|---|
| @@ -1,12 +1,101 @@ | ||
| const { JWK } = require('jose'); | ||
| /** | ||
| * ⚠️ WARNING: TEST KEYS ONLY - DO NOT USE IN PRODUCTION ⚠️ | ||
| * | ||
| * This file contains RSA private keys that are INTENTIONALLY PUBLIC for testing. | ||
| * These keys are: | ||
| * - FOR TESTING ONLY - Never use in production | ||
| * - PUBLICLY COMMITTED - Not secret, safe for test fixtures | ||
| * - DETERMINISTIC - Same keys every test run for reproducibility | ||
| * | ||
| * Pre-generated RSA-2048 key pair for testing. | ||
| * | ||
| * Note: jose v6 only provides async key generation (generateKeyPair), which cannot | ||
| * be used at module load time. Using a static key here is preferable for tests as it: | ||
| * - Ensures deterministic test results | ||
| * - Improves test performance (no generation overhead) | ||
| * - Simplifies debugging with consistent test data | ||
| * | ||
| * This key was originally sourced from examples/private-key.pem and matches the | ||
| * private key JWT example in the codebase. | ||
| * | ||
| * See end-to-end/fixture/README.md for more information on test key security. | ||
| * | ||
| * To regenerate if needed: | ||
| * ``` | ||
| * const { generateKeyPair, exportPKCS8, exportSPKI, exportJWK } = require('jose'); | ||
| * const { publicKey, privateKey } = await generateKeyPair('RS256', { modulusLength: 2048 }); | ||
| * const privatePEM = await exportPKCS8(privateKey); | ||
| * const publicPEM = await exportSPKI(publicKey); | ||
| * const privateJWK = await exportJWK(privateKey); | ||
| * const publicJWK = await exportJWK(publicKey); | ||
| * ``` | ||
| */ | ||
|
|
||
| const key = JWK.generateSync('RSA', 2048, { | ||
| const privatePEM = `-----BEGIN PRIVATE KEY----- | ||
| MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDbTKOQLtaZ6U1k | ||
| 3fcYCMVoy8poieNPPcbj15TCLOm4Bbox73/UUxIArqczVcjtUGnL+jn5982V5EiB | ||
| y8W51m5K9mIBgEFLYdLkXk+OW5UTE/AdMPtfsIjConGrrs3mxN4WSH9kvh9Yr41r | ||
| hWUUSwqFyMOssbGE8K46Cv0WYvS7RXH9MzcyTcMSFp/60yUXH4rdHYZElF7XCdiE | ||
| 63WxebxI1Qza4xkjTlbp5EWfWBQB1Ms10JO8NjrtkCXrDI57Bij5YanPAVhctcO9 | ||
| z5/y9i5xEzcer8ZLO8VDiXSdEsuP/fe+UKDyYHUITD8u51p3O2JwCKvdTHduemej | ||
| 3Kd1RlHrAgMBAAECggEATWdzpASkQpcSdjPSb21JIIAt5VAmJ2YKuYjyPMdVh1qe | ||
|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CD1k0hr1HH6qm5nYUb8JmY8KOr0CgYB85pvPhBqqfcWi6qaVQtK1 | ||
| ukIdiJtMNPwePfsT/2KqrbnftQnAKNnhsgcYGo8NAvntX4FokOAEdunyYmm85mLp | ||
| BGKYgVXJqnm6+TJyCRac1ro3noG898P/LZ8MOBoaYQtWeWRpDc46jPrA0FqUJy+i | ||
| ca/T0LLtgmbMmxSv/MmzIg== | ||
| -----END PRIVATE KEY-----`; | ||
|
|
||
| const publicPEM = `-----BEGIN PUBLIC KEY----- | ||
| MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA20yjkC7WmelNZN33GAjF | ||
| aMvKaInjTz3G49eUwizpuAW6Me9/1FMSAK6nM1XI7VBpy/o5+ffNleRIgcvFudZu | ||
| SvZiAYBBS2HS5F5PjluVExPwHTD7X7CIwqJxq67N5sTeFkh/ZL4fWK+Na4VlFEsK | ||
| hcjDrLGxhPCuOgr9FmL0u0Vx/TM3Mk3DEhaf+tMlFx+K3R2GRJRe1wnYhOt1sXm8 | ||
| SNUM2uMZI05W6eRFn1gUAdTLNdCTvDY67ZAl6wyOewYo+WGpzwFYXLXDvc+f8vYu | ||
| cRM3Hq/GSzvFQ4l0nRLLj/33vlCg8mB1CEw/LudadzticAir3Ux3bnpno9yndUZR | ||
| 6wIDAQAB | ||
| -----END PUBLIC KEY-----`; | ||
|
|
||
| // For JWK format | ||
| const privateJWK = { | ||
| kty: 'RSA', | ||
| kid: 'key-1', | ||
| use: 'sig', | ||
| alg: 'RS256', | ||
| n: '20yjkC7WmelNZN33GAjFaMvKaInjTz3G49eUwizpuAW6Me9_1FMSAK6nM1XI7VBpy_o5-ffNleRIgcvFudZuSvZiAYBBS2HS5F5PjluVExPwHTD7X7CIwqJxq67N5sTeFkh_ZL4fWK-Na4VlFEsKhcjDrLGxhPCuOgr9FmL0u0Vx_TM3Mk3DEhaf-tMlFx-K3R2GRJRe1wnYhOt1sXm8SNUM2uMZI05W6eRFn1gUAdTLNdCT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w8X2lj9143frnH64nNQFIFSKsCZIz5q_8TUY0bDY6GsZJnd2YAg4JtkRTY8tPcVjQU9fxxtFJ-X19uN1HNOulNBcCD1k0hr1HH6qm5nYUb8JmY8KOr0', | ||
| qi: 'fOabz4Qaqn3FouqmlULStbpCHYibTDT8Hj37E_9iqq2537UJwCjZ4bIHGBqPDQL57V-BaJDgBHbp8mJpvOZi6QRimIFVyap5uvkycgkWnNa6N56BvPfD_y2fDDgaGmELVnlkaQ3OOoz6wNBalCcvonGv09Cy7YJmzJsUr_zJsyI', | ||
| }; | ||
|
|
||
| const publicJWK = { | ||
| kty: 'RSA', | ||
| kid: 'key-1', | ||
| use: 'sig', | ||
| }); | ||
| alg: 'RS256', | ||
| n: '20yjkC7WmelNZN33GAjFaMvKaInjTz3G49eUwizpuAW6Me9_1FMSAK6nM1XI7VBpy_o5-ffNleRIgcvFudZuSvZiAYBBS2HS5F5PjluVExPwHTD7X7CIwqJxq67N5sTeFkh_ZL4fWK-Na4VlFEsKhcjDrLGxhPCuOgr9FmL0u0Vx_TM3Mk3DEhaf-tMlFx-K3R2GRJRe1wnYhOt1sXm8SNUM2uMZI05W6eRFn1gUAdTLNdCTvDY67ZAl6wyOewYo-WGpzwFYXLXDvc-f8vYucRM3Hq_GSzvFQ4l0nRLLj_33vlCg8mB1CEw_LudadzticAir3Ux3bnpno9yndUZR6w', | ||
| e: 'AQAB', | ||
| }; | ||
|
|
||
| module.exports.privateJWK = key.toJWK(true); | ||
| module.exports.publicJWK = key.toJWK(); | ||
| module.exports.privatePEM = key.toPEM(true); | ||
| module.exports.publicPEM = key.toPEM(); | ||
| module.exports.privateJWK = privateJWK; | ||
| module.exports.publicJWK = publicJWK; | ||
| module.exports.privatePEM = privatePEM; | ||
| module.exports.publicPEM = publicPEM; |
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
Oops, something went wrong.
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.
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!
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.
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.