Repository navigation
Description
Summary
Every RP site on the infodancer stack re-implements the same post-login glue: take the verified claims oidclient produced, upsert a local users row keyed by subject, and put the local user ID in the session. Two sites carry near-identical copies today:
- OSG:
server/internal/web/users.go(165 lines) + the sync half ofauth.go - SF:
internal/web/auth.go(202 lines)
SF's 006_users.sql is a near-verbatim copy of OSG's 002_users.sql (same oidc_sub key, same email/name/roles/email_verified columns). A third site will copy it again. This is security-sensitive policy code; it should be written once and audited once.
Companion to infodancer/web#52 (web/profile), which deliberately excludes this -- profile keys on an opaque host user key and works with or without this extraction.
What the shared part actually is
Not the table -- the policy:
- Key strictly on (issuer, subject). Never match or merge accounts by email: an upstream that recycles or reassigns an email must not grant access to an existing local account.
- On each login, refresh mutable claims (email, display name, email_verified) on the existing row; never create a second row for a known subject.
- Record
email_verifiedand expose it so hosts can gate features on it (OSG'srequire_verifiedpattern). - Map role claims into host roles in one place.
- The session carries the local user key, not raw claims.
What stays host-owned
The users table. Both sites FK their schemas into users.id (OSG: campaigns, characters, memberships; SF: authors.claimed_by) -- it is the host's FK hub, and each host has host-specific columns. So the extraction is interface-shaped, not table-shaped, and oidclient stays free of database dependencies:
// Identity is the normalized result of a completed login.
type Identity struct {
Issuer string
Subject string
Email string
EmailVerified bool
DisplayName string
Roles []string
}
// UserStore is implemented by the host over its own users table.
type UserStore interface {
// UpsertBySubject creates or updates the host's user row for this
// identity, keyed on (Issuer, Subject) only, and returns the host's
// stable user key.
UpsertBySubject(ctx context.Context, id Identity) (string, error)
}oidclient gains a callback helper (or middleware) that runs code exchange -> claim validation -> Identity -> store.UpsertBySubject -> session, so hosts keep their schema and sqlc and delete the policy code. The returned user key is also exactly what web/profile wants as its user_key.
Placement
Subpackage (e.g. oidclient/rpuser) unless the API folds cleanly into the root package. Either way: no pgx, no goose -- the host owns storage.
Non-goals
- A module that owns a users table. Greenfield sites might want that someday; it would be a separate component with the FK-hub tradeoffs made explicit, not this issue.
- Blocking profile: new component for the public persona (handle, display name, bio, avatar, links) web#52 -- that ships against the hosts' existing user keys first.
Consumers
OSG and SF delete their duplicated sync code; any new site starts from the audited path instead of copying users.go a third time.
Activity
matthewjhunter commentedon Jul 18, 2026
Re-verified this against current OSG and SF code (2026-07-18). The core premise still holds -- posting a correction on two points before anyone implements against it.
Still accurate
getOrProvisionUser(server/internal/web/auth.go:393-457) and SF's (internal/web/auth.go:282-313) are structurally identical -- sameGetByOIDCSub-> syncemail/email_verifiedon hit ->name := claims.Name; if name == "" { name = claims.Email }fallback ->CreateUseron miss.002_users.sqland SF's006_users.sqldiff to identical columns (id,oidc_subunique,email,name,roles text[],created_at,updated_at) -- SF just splitemail_verifiedinto a follow-up migration (007_user_email_verified.sql) instead of the initial one.rpuserpackage, noIdentity/UserStoretypes in oidclient.infodancer/web#52, profile) shipped 2026-06-09, so the opaque host user key this doesn't block on already exists.Needs correction
"Map role claims into host roles in one place" isn't something either site actually does.
oidclient.Claimsdoes carry aRoles []stringfield, but neither OSG nor SF ever readsclaims.Roles. Both sites'Rolescome from the persistedusers.rolesDB column, set out-of-band (admin action), not from the ID token. OSG went further and moved role resolution to a separate authz grants service on 2026-05-19 -- three weeks before this issue was filed -- with a comment inauth.goexplicitly callingusers.roles"legacy." This bullet should be dropped from the shared-policy list, or theIdentitystruct should dropRoles(or keep it but document that hosts are free to ignore it, since real role authority already lives elsewhere).Identity.Issuercan't be populated fromoidclient.Claimsas currently shaped.Claimshas noissfield. OSG'snotifyActorhas to work around this today by injectings.config.OIDCIssuerURLfrom its own config rather than the claims (see the comment atauth.go:462-464: "since oidclient.Claims does not surface iss"). Whatever consumes the proposedUserStore.UpsertBySubject(ctx, id Identity)needs a documented answer for whereIssuercomes from -- host config, notClaims-- oroidclient.Claimsneeds anIssuerfield added alongside this work.Everything else in the issue (the
Identity/UserStoreshape, therpusersubpackage placement, the non-goals, "what stays host-owned") still reads correctly against current code.matthewjhunter commentedon Jul 18, 2026
Design review against the full auth stack (2026-07-18), including infodancer/authz, which the original issue predates in deployment (both sites now run it). The premise holds -- extract once, audit once -- but the spec needs revision on five points before implementation. This supersedes the bullet-level corrections in my previous comment by folding them into a coherent revision.
1.
authz.Identityalready exists and is the shape this issue wantsThe proposed
rpuser.Identityreinventsauthz.Identity(Issuer, Subject, DisplayName, Email, EmailVerified) almost field-for-field. That type is deployed in both OSG and SF today via each site'sauthzsrc.go-- two files that are byte-identical except for the repo name in a comment, i.e. yet another copy of the same glue this issue exists to kill.The revision:
rpuser's identity type should mirrorauthz.Identity's field names and semantics exactly (DisplayName, notName), so the host's conversion between the two is mechanical. Keep the libraries decoupled -- oidclient should not import authz; identical shape without the dependency is enough.2. Drop
Rolesfrom the struct -- it contradicts the authz design, not just current practiceMy earlier comment noted neither site reads
claims.Roles. It is stronger than that: authz's DESIGN.md makes "claims never carry roles" a trust-model invariant and lists JIT seeding from JWT claims as an explicit non-goal ("a federation footgun"). Both sites resolve roles through authz's(issuer, subject, module, role)store, granted out-of-band. ARolesfield on the extracted identity type would invite exactly the pattern the authorization layer was built to forbid. Remove it; the "map role claims into host roles in one place" bullet goes with it.3. The
Issuerquestion is already answered -- twice, identicallyBoth
authzsrc.gocopies carry the same comment: the issuer is the host-configured OIDC issuer URL, not a token claim, becauseoidclient.Claimsdoesn't surfaceissand oidclient validates the token'sissagainst the configured issuer during verification anyway. So the configured value is the authoritative one, and authz grants are keyed on that same string.The clean implementation follows directly: the rpuser helper fills
Identity.Issuerfrom the client's own verifiedIssuerURLconfig. (SurfacingissinClaimsremains a reasonable independent improvement, but nothing here blocks on it.)4. Keying: the users tables and the authz store disagree today
The issue says "key strictly on (issuer, subject)" -- but both sites' users tables key on
oidc_subalone (no issuer column), while authz already keys grants on the composite. That skew is currently harmless only because each site has exactly one upstream fixed by config. It means the extraction has a real migration decision, not a doc note:issuerto the users tables and widen the unique constraint as part of adopting rpuser. Matches authz, closes the multi-issuer gap for good.Either is defensible; the spec should pick one explicitly. My lean is align-now: the migration is small while there are two consumers, and it makes the user store and the role store agree on what identifies a person.
5. Scope: the callback half is only half the duplication
The issue extracts login-time provisioning, but the per-request half is duplicated just as verbatim: both sites'
optionalAuthmiddleware runsessions.Authenticate-> resolve/provision the local user -> stash user + claims in context, and bothauthzsrc.gofiles feed authz from those stashed claims. Two consequences:sessionsubpackage deliberately keeps tokens server-side and returns claims per request, because renewal happens per request and refreshed tokens carry refreshed claims. The local user is re-derived each request from those claims. Storing the user key at callback time and stopping there would fight that design. Drop the bullet; the extraction should standardize the per-request resolve path instead.Revised sketch
plus two integration points instead of one:
CallbackOptions.OnAuthenticatedadapter (or wrapper) that buildsIdentityfrom claims + configured issuer and callsUpsertBySubject. The name-fallback policy (DisplayName = Name, else Email) lives here, once, instead of in four places across two repos.session.Manager.Authenticatethat resolves claims ->Identity-> host user viaLookupBySubject(read-only, per the sync decision above), and stashes both in context -- replacing each site's hand-rolledoptionalAuth+authzsrc.gopair. authz'sIdentitySourcecan then be implemented once against the stashed identity.Non-goals unchanged: no table ownership, no pgx/goose, hosts keep their schema and sqlc. Consumers unchanged: OSG and SF delete their copies; site three starts from the audited path.
matthewjhunter commentedon Jul 18, 2026
Decision on point 4: align now. Both OSG and SF migrate their users tables to key on (issuer, subject) -- add the issuer column, widen the unique constraint -- as part of adopting rpuser, so the user store and the authz grant store agree on what identifies a person. No deferred single-issuer carve-out. All five points are now settled; the revised sketch in the previous comment is the implementation spec.
rpuser: audited claims -> local-user provisioning path (#25)