Skip to content

feat: first-party role guard and the organization on User - #28

Merged
Bccorb merged 2 commits into
mainfrom
feat/first-party-role-guard
Nov 1, 2026
Merged

Bccorb merged 2 commits into
mainfrom
feat/first-party-role-guard

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Closes #25.

What

  • Adapter.RequireRole(roles ...string): middleware for first-party sessions. It passes when any listed role is granted by any of the session's roles, matched with RoleGrantsAccess (the port of roleGrantsAccess in @seamless-auth/types). Roles come from the verified access token only. Responses:

    • 401 {"error":"unauthenticated"} for no session, an invalid one, or an ephemeral token
    • 403 enrollment_required for a recovery session unless AllowRecoverySessions is set
    • 403 cross_site_request_blocked for a cookie session that fails the origin check
    • 403 insufficient_role when no listed role is granted

    Bodies never carry the user's roles or the required ones. It panics on no role or an empty role, as Verifier.RequireRole does. RequireAuth is unchanged; both share one session helper.

  • User.OrganizationID: the org_id claim of the verified access token, for cookie and bearer sessions alike. The cookie's unsigned organizationId copy is not read.

  • Logout clears PreAuthCookieName when it differs from RegistrationCookieName.

  • README: a Roles section, the new field, and the options rows that changed.

The same guard and field are landing in the Python and Rust adapters and in @seamless-auth/nextjs, with the same responses.

Checks

  • gofmt clean, go vet ./... clean, go test -race -count=1 ./... ok.
  • scripts/api-check.sh: compatible changes only ((*Adapter).RequireRole, User.OrganizationID added), suggested v0.5.0.
  • scripts/check-manifest.sh passes.

Logout cleared the access, registration and refresh cookies only, so a PreAuthCookieName that differs from RegistrationCookieName was left behind.

Refs #25
Adapter.RequireRole guards a route on the session's roles, matched as RoleGrantsAccess does, with the roles of the verified access token. It answers 401 unauthenticated without a session, 403 enrollment_required for a recovery session, 403 cross_site_request_blocked for a cross-site cookie request and 403 insufficient_role when no listed role is granted, and panics when given no role.

User.OrganizationID is the org_id claim of the verified access token, for cookie and bearer sessions alike.

Closes #25
@Bccorb
Bccorb merged commit 85aacec into main Nov 1, 2026
5 checks passed
@Bccorb
Bccorb deleted the feat/first-party-role-guard branch November 1, 2026 21:29
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.

feat: first-party role guard and organization on User

1 participant