Repository navigation
feat: first-party role guard and the organization on User - #28
Merged
Merged
Conversation
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
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.
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 withRoleGrantsAccess(the port ofroleGrantsAccessin@seamless-auth/types). Roles come from the verified access token only. Responses:{"error":"unauthenticated"}for no session, an invalid one, or an ephemeral tokenenrollment_requiredfor a recovery session unlessAllowRecoverySessionsis setcross_site_request_blockedfor a cookie session that fails the origin checkinsufficient_rolewhen no listed role is grantedBodies never carry the user's roles or the required ones. It panics on no role or an empty role, as
Verifier.RequireRoledoes.RequireAuthis unchanged; both share one session helper.User.OrganizationID: theorg_idclaim of the verified access token, for cookie and bearer sessions alike. The cookie's unsignedorganizationIdcopy is not read.Logout clears
PreAuthCookieNamewhen it differs fromRegistrationCookieName.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
go vet ./...clean,go test -race -count=1 ./...ok.scripts/api-check.sh: compatible changes only ((*Adapter).RequireRole,User.OrganizationIDadded), suggested v0.5.0.scripts/check-manifest.shpasses.