Repository navigation
Require login with Entra ID or a password for all of Saman - #23
Merged
Merged
Conversation
Nothing is available without logging in (NF-11). The Astro middleware asks Payload who the session cookie belongs to and sends everyone else to /logg-inn. Payload stays the only session and the only access control. - Entra ID (NF-02): the CMS runs the OpenID Connect authorization code flow with PKCE and issues a normal Payload session. Users are found by their Entra oid, created on first login, and linked to an existing user with the same email. The provider list is built for Ansattporten (NF-13) to join later. - Email and password (NF-12) stays as the fallback, on /logg-inn and in the admin panel. - Everyone in Digdir can now log in, so only administrators use the admin panel and change users and media. The first user becomes one, and `pnpm make-admin` promotes others. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first-user rule is for the form on /admin of an empty database. On a fresh deployment, whoever happened to log in with Entra ID first would otherwise have become an administrator. CI caught it: its database is empty when the Entra ID tests run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Users get firstName and lastName, from the optional claims given_name and family_name, instead of the display name, which Entra ID writes as «Birkeli, Ronny». A name the token doesn't carry is left as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 1, 2026
RonnyB71
added a commit
that referenced
this pull request
Nov 1, 2026
The overview described an earlier plan: the frontend getting an Entra ID access token for the CMS, and the CMS validating it. What was built (#23, ADR-0001) runs the sign-in in the CMS and has both apps share Payload's session. The Mermaid source, the redrawn SVG, the authentication steps, the parts table and the local setup now say so. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
RonnyB71
added a commit
that referenced
this pull request
Nov 1, 2026
docs/adr/ records why Saman is built the way it is, next to the specification's own log of requirement changes. ADR-0001 writes down the login design from #21 and #23 (NF-02, NF-11, NF-12, NF-13) as accepted. ADR-0002 proposes limiting password login (NF-12) to named break-glass accounts, for discussion on this pull request. CLAUDE.md says when to write a record and that proposed ones aren't built. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements login for the first version, as decided in #21: nothing in Saman is available without logging in.
Requirements: NF-11, NF-02, NF-12, and groundwork for NF-13.
How it works
payload-tokencookie. Access control stays in the collection access functions.src/web/src/middleware.ts) asks Payload's/api/brukere/mewho the cookie belongs to on every request./logg-inn?redirect=….src/cms/src/auth/) usesopenid-clientwith the authorization code flow and PKCE.tidmust matchENTRA_TENANT_ID.oid, created on first login, and linked by email to an existing user.given_nameandfamily_name, which must be turned on in the app registration. A name the token doesn't carry is left unchanged.ENTRA_*variables the provider is off, and only email and password are offered./logg-innand in the admin panel. Users created by Entra ID get a random password, so the fallback works only for users an administrator has given a password.identitiesarray of{ provider, subject }, and providers are a list. Ansattporten becomes one more entry once open question 8 is answered.Changes to access
Now that everyone in Digdir can log in, the collections that let any logged-in user write had to be tightened:
roles: ['admin']) can use the admin panel, read other users, or create, update and delete users and media.pnpm make-admin <email>promotes an existing user. Existing dev databases: users from before this PR have no role, so run it once for yourself.Other changes
OriginorSec-Fetch-Siteheader for its CSRF check. So the newauthHeaders(cookie)in@saman/sharedsends the token asAuthorization: JWT …. CLAUDE.md now says pages read as the visitor./now redirects to the web frontend. The e2e readiness check waits on/api/healthinstead.Tests
pnpm lintpasses.pnpm test: CMS 26 passed, web 14 passed.pnpm test:e2e: 9 passed.oauth2-mock-server, covering first login, finding the user byoidafter an email change, linking by email, another tenant, a tampered state cookie, the redirect allow-list, and the provider being off. Also access tests for users and media.Setup for a local Entra ID login
Set
ENTRA_TENANT_ID,ENTRA_CLIENT_IDandENTRA_CLIENT_SECRETinsrc/cms/.env. The redirect URI ishttp://localhost:3000/api/brukere/oauth/entra/callback. The values are not committed.🤖 Generated with Claude Code