Skip to content

Fix invalid shipped OIDC authentication.toml example#4123

Open
lunkwill42 wants to merge 5 commits into
Uninett:5.19.xfrom
lunkwill42:bugfix/oidc-scope-config-4121
Open

Fix invalid shipped OIDC authentication.toml example#4123
lunkwill42 wants to merge 5 commits into
Uninett:5.19.xfrom
lunkwill42:bugfix/oidc-scope-config-4121

Conversation

@lunkwill42

Copy link
Copy Markdown
Member

Scope and purpose

Fixes #4121.

The OIDC example shipped in webfront/authentication.toml no longer validated against the Pydantic config models introduced in #4025, so a user who copied it hit a ValidationError and NAV refused to start. Two things were wrong: scope was documented at the IdP entry level, which OIDCProviderEntry rejected (extra="forbid"), and the settings section was mis-spelled [oidc.dataporten-oidc.settings], missing the .idps. segment.

Rather than force scope into the [...settings] sub-table, this restores it as a first-class entry-level field on OIDC providers — matching how social providers already expose scope — and routes it into allauth's per-APP settings, where the openid_connect provider reads it. Entry-level scope takes precedence over any value passed through the settings passthrough. The shipped example and the reference docs are corrected to match, and a regression test now enables the bundled example and asserts the whole file validates.

A reviewer can observe the effect by uncommenting the OIDC example block in python/nav/etc/webfront/authentication.toml and starting NAV: before this change it raises a ValidationError at startup, after it loads cleanly.

Contributor Checklist

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

The Pydantic rewrite (Uninett#4025) dropped OIDC's entry-level `scope`, which
`OIDCProviderEntry` then rejected via `extra="forbid"`. Restore it as a
real field and route it into the generated per-APP allauth settings,
where the openid_connect provider reads it via `app.settings["scope"]`.
Entry-level scope takes precedence over any value smuggled in through
the `[...settings]` passthrough.

This mirrors how `SocialProviderEntry` already exposes `scope`.
The bundled authentication.toml documented `scope` at the IdP entry
level (now valid again) but also mis-spelled the settings section as
`[oidc.dataporten-oidc.settings]`, dropping the `.idps.` segment.
Copying the example verbatim produced a startup ValidationError.

Correct the section path and apply the same fix to the stale docstring
in the legacy OIDCConfigParser.
Align the reference guide with the shipped example: document `scope` at
the IdP entry level rather than under `[...settings]`, and drop the
`# scope = [],` line whose trailing comma is invalid TOML if uncommented.
Cover entry-level scope routing and its precedence over settings-level
scope, plus a regression test that enables the examples in the shipped
authentication.toml and asserts the whole file validates.
@lunkwill42 lunkwill42 self-assigned this Jul 8, 2026
@lunkwill42
lunkwill42 requested a review from a team July 8, 2026 12:56
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.36%. Comparing base (5b71398) to head (6545ed3).

Additional details and impacted files
@@            Coverage Diff             @@
##           5.19.x    #4123      +/-   ##
==========================================
- Coverage   65.39%   65.36%   -0.03%     
==========================================
  Files         629      629              
  Lines       47191    47194       +3     
==========================================
- Hits        30861    30850      -11     
- Misses      16330    16344      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}
# Pass through any extra provider-specific settings
settings.update(entry.settings.model_extra)
# Entry-level scope (the documented spelling) wins over any scope

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

remove parens

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What I meant here is that I would suggest rather (the documented level)

@johannaengland
johannaengland self-requested a review July 9, 2026 09:21

@johannaengland johannaengland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just the nitpick about the comment

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