GovWrenv0.10.0
GitHub

Single sign-on

GovWren can let people sign in with the account your organization already gives them, through any identity provider that speaks OpenID Connect. This guide sets it up, with the exact steps for Microsoft Entra ID, and explains how the provider's groups become roles in GovWren.

Single sign-on is optional. Without it, people sign in with a password that GovWren keeps, as described in Getting started.

How it works#

  1. A person chooses Sign in with your organization account on the sign-in page.
  2. GovWren sends the browser to your identity provider, which signs the person in as it always does.
  3. The provider sends the browser back with a one-time code. GovWren exchanges the code for a signed ID token and checks its signature, issuer, audience, expiry, and that it answers this sign-in and no other.
  4. GovWren finds the person's account, or creates it, and gives them the roles their groups map to.

GovWren uses the authorization code flow with PKCE. It accepts ID tokens signed with RS256 and refuses anything else. It never sees the person's password.

What you need#

Set it up with Microsoft Entra ID#

1. Register GovWren#

In the Entra admin center, under App registrations, choose New registration.

FieldValue
NameGovWren
Supported account typesAccounts in this organizational directory only
Redirect URIPlatform Web, address https://govwren.example.org/api/v1/sso/callback (your own address)

After it is created, note two values from its Overview page: the Application (client) ID and the Directory (tenant) ID.

2. Create a client secret#

Under Certificates & secrets, add a New client secret. Copy its Value now; it is shown once. Note when it expires: sign-in stops working on that day until you replace it.

3. Send groups or application roles in the token#

GovWren reads one claim from the ID token to learn what a person belongs to. Choose one of these.

Application roles (recommended). Under App roles, create a role for each kind of access, for example Governance, Auditor, PrivacyReviewer. Then, under Enterprise applications → GovWren → Users and groups, assign people or groups to those roles. Entra sends them in a claim named roles, by the role's Value. Names are stable and readable, and only what you assigned is sent.

Security groups. Under Token configuration, choose Add groups claim and select Security groups for the ID token. Entra sends them in a claim named groups, by each group's object ID. If a person is in more groups than fit in a token, Entra leaves the claim out. GovWren then leaves that person's roles as they were, and writes a line to its log, so that nobody loses access because of it. To avoid this, choose Groups assigned to the application in the same dialog.

4. Tell GovWren#

In govwren.toml:

[server]
base_url = "https://govwren.example.org"

[sso]
issuer = "https://login.microsoftonline.com/YOUR-TENANT-ID/v2.0"
client_id = "YOUR-APPLICATION-CLIENT-ID"
groups_claim = "roles"        # or "groups", if you chose security groups
trust_email = true

Put the client secret in the environment of the GovWren server, never in the file:

export GOVWREN_SSO_CLIENT_SECRET='the secret value'

Then check and restart:

uv run govwren doctor

doctor reads the provider's discovery document and says whether the secret is set.

trust_email = true is right for a single-tenant registration, because every address the tenant sends belongs to the person signing in. Entra does not mark addresses as verified, so without this setting GovWren would not join a first sign-in to an account that already exists. Leave it false for a provider that lets people enter any address they like.

5. Map groups to roles#

Sign in to GovWren as an administrator and open Admin → Single sign-on. The page shows the connection and the redirect address to register. Under Groups and roles, add a line for each group or application role:

Group or application roleRole in GovWrenFor
GovernanceGovernanceEverywhere
AuditorAuditorEverywhere
PrivacyReviewerReviewerPrivacy
NeuroscienceLeadsSteward of a unitNeuroscience
HaleLabMember of a unitHale Lab

Enter each value exactly as the provider sends it: the role's Value for application roles, or the object ID for security groups.

The Single sign-on page under AdminThe Single sign-on page under Admin
Admin → Single sign-on, before a provider is connected

How accounts and roles behave#

Turn off passwords#

Once single sign-on works, you can stop password sign-in for everyone except administrators:

[sso]
local_sign_in = false

Administrators keep their passwords as the way in when the provider cannot be reached. Keep at least one such account, with a long password stored somewhere safe.

Settings#

Key in [sso]DefaultMeaning
issuer""The provider's issuer address. Empty turns single sign-on off
client_id""The identifier the provider gave GovWren
client_secret_env"GOVWREN_SSO_CLIENT_SECRET"The name of the environment variable that holds the client secret
scopes"openid profile email"What GovWren asks the provider for. Must include openid
groups_claim"groups"The claim that lists a person's groups or application roles
label"Sign in with your organization account"The words on the sign-in button
trust_emailfalseJoin existing accounts by the address the provider sends, even if it is not marked verified
local_sign_intruefalse keeps password sign-in for administrators only

When sign-in fails#

The sign-in page says only that it did not work. The reason is in GovWren's log, on a line beginning single sign-on.

The log saysWhat to check
the client secret is not setThe environment variable named by client_secret_env is set for the server process
the identity provider refused the codeThe client secret is current, and the redirect address registered at the provider is exactly <base_url>/api/v1/sso/callback
describes a different issuerissuer matches the provider's discovery document exactly, including /v2.0 for Entra
the ID token was not accepted: meant for another applicationclient_id is this application's
did not send an email address it vouches forAdd the email scope or claim at the provider, or set trust_email for a provider you control
unknown or expired stateThe person took more than ten minutes, or used the back button. Trying again works

Try it without a real provider#

The repository includes a stand-in provider for development. It has a few sample people and no passwords, and its signing key is public, so it proves nothing about anyone. Never use it for real sign-in.

uv run python scripts/dev_identity_provider.py     # http://127.0.0.1:8099
[sso]
issuer = "http://127.0.0.1:8099"
client_id = "govwren-dev"
trust_email = true

Start GovWren with GOVWREN_SSO_CLIENT_SECRET=dev-secret. GovWren accepts an http issuer only on this machine.

Describes GovWren 0.10.0. Apache License 2.0. Screenshots show an invented organization; every person and record in them is fictional.