feat(#10650): support configuring max_age parameter for OIDC login#10801
feat(#10650): support configuring max_age parameter for OIDC login#10801saurabh12nxf wants to merge 3 commits intomedic:masterfrom
Conversation
jkuester
left a comment
There was a problem hiding this comment.
Looking good @saurabh12nxf!
Can you also update the integration tests to test this logic. Basically we want to confirm that when max_age is configured, it is passed as a param. Then, when the server returns the auth_time, we should confirm (if possible) that the value of the claim is validated (and very old auth times are rejected). We don't need to get too crazy checking every edge case, but it would be nice to hit the happy path for max_age and then have one test that does fail the auth_time validation. Probably will require changes to our mock oidc provider.
| if (oidcProvider.max_age !== undefined && oidcProvider.max_age !== null) { | ||
| params.max_age = oidcProvider.max_age; | ||
| } | ||
|
|
There was a problem hiding this comment.
Minor, but I guess we can just directly pass the max_age value here.
| const { idServerConfig, oidcProvider } = await oidcServerSConfig(); | |
| const params = { | |
| redirect_uri: redirectUrl, | |
| scope: 'openid email', | |
| max_age: oidcProvider.max_age | |
| }; |
| const checks = { idTokenExpected: true }; | ||
| if (oidcProvider.max_age !== undefined && oidcProvider.max_age !== null) { | ||
| checks.maxAge = oidcProvider.max_age; | ||
| } |
There was a problem hiding this comment.
| const checks = { idTokenExpected: true }; | |
| if (oidcProvider.max_age !== undefined && oidcProvider.max_age !== null) { | |
| checks.maxAge = oidcProvider.max_age; | |
| } | |
| const checks = { | |
| idTokenExpected: true, | |
| maxAge: oidcProvider.max_age | |
| }; |
Should be able to just set this directly.
Looking at the oauth4webapi validation logic (used under the hood by openid-client) when the auth_time is validated, it is with a default tolerance of 30s which should be fine for our purposes.
We do need to bump the version of the openid-client dependency in the root package.json to the latest release (6.8.2) so that we get this fix for max_age: 0... 😅
|
Thanks for the review @jkuester! I've made the requested changes:
For the integration tests, I'd appreciate some guidance on how to set up the mock OIDC provider to test the max_age flow and auth_time validation. Should I look at extending the existing mock provider in |
The That mock provider is effectively just an Express server that "handles" OIDC requests as if it was a real OIDC provider. We will need to make some kind of updates to this service (I have not had a chance to look too closely yet). Basically it I think we need some logic to have it return the |
Description
This PR implements support for the OIDC
max_ageparameter to address issues with shared device scenarios where users may be automatically logged in as the previous user without being prompted for authentication.Changes Made
Modified
api/src/services/sso-login.js:oidcServerSConfig()to return bothidServerConfigandoidcProvidersettingsmax_ageparameter to authorization URL when configured inoidc_providersettingsmaxAgevalidation to token verification to check theauth_timeclaimAdded comprehensive test coverage in
api/tests/mocha/services/sso-login.spec.js:max_ageparameter in authorization URL (normal case)max_age: 0edge case in authorization URLmaxAgevalidation in token verification (normal case)maxAge: 0edge case in token verificationHow It Works
When
max_ageis configured in theoidc_providersettings, the OIDC authorization flow will:max_ageparameter in the authorization URL sent to the auth providermax_ageseconds, the user will be prompted to re-authenticateauth_timeclaim which is validated against the configuredmaxAgeConfiguration
Add
max_age(in seconds) to theoidc_providerconfiguration in the instance settings document:{ "oidc_provider": { "discovery_url": "https://auth-provider.com/.well-known/openid-configuration", "client_id": "your-client-id", "max_age": 60 } }Setting max_age: 0 is equivalent to prompt=login per the OIDC specification, forcing immediate re-authentication.
Fixes #10650
Code review checklist
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.