Skip to content

feat(api): look up, accept and decline invitations by link - #3025

Closed
vitorbari wants to merge 6 commits into
mainfrom
2853-invitation-redeem
Closed

vitorbari wants to merge 6 commits into
mainfrom
2853-invitation-redeem

Conversation

@vitorbari

@vitorbari vitorbari commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Context

Summary

  • POST /invitations/lookup returns the project, its name, the role, the expiry and the inviter:
    • inviter is a user-ref (user_id, identifier, display) the server resolves, because the invited user cannot read platform users and the console could not name the inviter from created_by alone;
    • it degrades to user_id when the inviter no longer resolves, and is null when a project secret created the invitation. created_by is unchanged.
  • POST /invitations/accept runs in one transaction:
    • the invitation must be pending and unexpired, its project claimed, and the accepting user not the inviter (403 inv.self_accept);
    • unless created_by is null, the inviter must still hold admin on the project, checked through the resolver on the transaction's statements; otherwise 403 inv.inviter_not_admin (new code);
    • the guarded status change runs first, so of two racing accepts the loser misses and gets the same 404 as a finished invitation;
    • the project_member adapter then calls GrantService.EnsureUserGrant: no grant is created, a different relation gets a second grant, an identical active grant counts as done, an identical expired grant is revoked and created again. It runs in the invitation's transaction, because Create opens its own and transactions don't nest, and it refuses a relation outside viewer, editor and admin, which accept answers as a server fault;
    • metadata is cleared and invitation.accepted emitted, sharing its request_id with the grant's authz.granted / authz.revoked.
  • POST /invitations/reject sets rejected, clears metadata and emits invitation.rejected. The inviter can't decline their own invitation (403 inv.self_reject, new code); they cancel it instead.
  • All three need a session of a user homed in the platform project; any other session gets 401. Accept and reject need the CSRF token, lookup doesn't. Every unknown or finished token answers the same 404 inv.not_found.
  • invitation.accepted and invitation.rejected move from the events catalog's Contracted table to Path B, and the stubs are gone.
  • Follow-up from the review of feat(api): invitations CRUD #2983: HTTP integration tests for the pending cap and replace at it, pagination, a concurrent replace, and another project's invitation ids.

Notes

  • The contract changes (inviter, self-decline) land with the implementation rather than in a spec PR first; happy to split them out.
  • Whoever holds a link sees the inviter's display name and identifier (usually their email), as ADR 086's accept page intends.
  • No rate limit yet. The server has no per-operation limiter anywhere (ADR 078, Rate limit grant creation by identifier #1266); the 128-bit token makes guessing infeasible meanwhile.
  • One race remains: the same user accepting two different invitations for the same relation at the same moment can still hit the grant's unique index and get a 500. Fixing that needs an insert that ignores conflicts in storage.
  • The console PR (feat(console): invite colleagues to a project by link and accept or decline an invitation #2978) can switch its invitation page from created_by to inviter.
  • TestSessionCSRF's lookup subtest expected the stub's 501; it now signs in a platform user and expects 404.
  • Integration tests ran on SQLite only (no Docker locally); Postgres and Spanner run in CI.

🤖 Generated with Claude Code

vitorbari and others added 2 commits November 12, 2026 11:33
A signed-in platform user redeems an invitation link (ADR 086 §3, §4, §7,
§10). Lookup returns the project, role, inviter and expiry. Accept marks
the invitation accepted under the pending guard, then the project_member
adapter grants the role through the grant service in the same
transaction. Decline marks it rejected. Every unknown or finished token
answers the same 404.

Accept is refused when the inviter accepts their own invitation, the
project is unclaimed, or the creator no longer holds admin
(inv.inviter_not_admin). invitation.accepted and invitation.rejected move
from the catalog's Contracted table to live producers.

Refs #2853

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd foreign ids over HTTP

Follow-up from the review of #2983: the cap and replace at it, pagination,
a concurrent replace and another project's invitation ids had been checked
by hand, but none had an HTTP-level integration test.

Refs #2852

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Nov 12, 2026 12:34pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 8f5f8b2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@zitadel/server Minor
@zitadel/cli Minor
@zitadel/testing Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-darwin-arm64 Minor
@zitadel/server-win32-x64 Minor
@zitadel/api Minor
@zitadel/config Minor
@zitadel/components Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-react Minor
@zitadel/sdk-vue Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/cloud Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…invitation

Lookup returns the inviter as a user reference, resolved by the server:
the invited user cannot read platform users, so the console had no way
to show who invited them from created_by alone. Decline now refuses the
inviter with inv.self_reject, as accept already did; an administrator
cancels their own invitation instead. EnsureUserGrant starts a span like
every other service method.

Refs #2853

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EnsureUserGrant refuses a relation outside viewer, editor and admin; the
invitation adapter answers that refusal as a server fault, since create
already validated the stored relation. ADR 086 gets a dated amendment for
the adapter's grant call, accept's ordering, self-decline and the named
inviter on lookup.

Refs #2853

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Invitation redemption lacks active-user validation, allowing deactivated users to accept or reject invitations, and delegated grants can incorrectly satisfy acceptance without creating a direct grant.

2 open issues
What changed in this PR

Implements link-based invitation lookup, acceptance, and decline, building on the invitation CRUD API and enabling the Console’s invitation journey.

Changes:

  • Replaces endpoint stubs with session-authenticated redemption, transactional grant handling, and audit events.
  • Adds resolved inviter details and new refusal codes to the API contract and generated Go bindings.
  • Expands service and HTTP integration coverage and updates lifecycle documentation and release notes.
File Description
packages/​go/​api/​oas_validators_gen.go Generates inviter-reference validation.
packages/​go/​api/​oas_schemas_gen.go Adds client inviter and error types.
packages/​go/​api/​oas_json_gen.go Adds client JSON handling for contract changes.
packages/​go/​api/​oas_client_gen.go Updates generated decline documentation.
docs/​design/​api/​events-catalog.md Marks acceptance and rejection events as emitted.
docs/​adrs/​086-invitations.md Documents redemption and grant-handling amendments.
apps/​api/​internal/​service/​invitation.go Implements lookup, acceptance, decline, and events.
apps/​api/​internal/​service/​invitation_test.go Tests redemption behavior and refusal cases.
apps/​api/​internal/​service/​grant.go Adds transactional grant reuse and replacement.
apps/​api/​internal/​service/​grant_test.go Tests rejection of unsupported grant relations.
apps/​api/​internal/​domain/​invitation.go Defines self-decline and inviter-authority errors.
apps/​api/​internal/​audit/​catalog_producers_test.go Registers the newly emitted invitation events.
apps/​api/​internal/​api/​security.go Registers redemption as user-session operations.
apps/​api/​internal/​api/​invitation.go Implements handlers, session checks, and error mapping.
apps/​api/​internal/​api/​integration_test/​invitation_test.go Covers redemption, limits, pagination, and isolation.
apps/​api/​internal/​api/​integration_test/​helpers/​server.go Wires grant and user-reference dependencies.
apps/​api/​internal/​api/​integration_test/​csrf_test.go Updates lookup coverage for the implemented endpoint.
apps/​api/​internal/​api/​generated/​oas_validators_gen.go Generates server inviter-reference validation.
apps/​api/​internal/​api/​generated/​oas_unimplemented_gen.go Updates generated decline documentation.
apps/​api/​internal/​api/​generated/​oas_server_gen.go Updates server-interface decline documentation.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Adds server inviter and error types.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Adds server JSON handling for contract changes.
apps/​api/​internal/​api/​generated/​oas_handlers_gen.go Updates generated handler documentation.
apps/​api/​cmd/​server/​server.go Wires invitation-service dependencies at startup.
apps/​api/​api/​openapi/​endpoints/​invitations/​reject/​rejectInvitation-error-response.yaml Updates generated decline error responses.
apps/​api/​api/​openapi/​endpoints/​invitations/​reject/​methods.yaml Documents the self-decline restriction.
apps/​api/​api/​openapi/​endpoints/​invitations/​lookup/​invitation-lookup-common.yaml Defines the nullable inviter reference.
apps/​api/​api/​openapi/​endpoints/​invitations/​accept/​acceptInvitation-error-response.yaml Updates generated acceptance error responses.
apps/​api/​api/​openapi/​endpoints/​events/​webhooks/​invitation-rejected.yaml Removes the not-yet-emitted notice.
apps/​api/​api/​openapi/​endpoints/​events/​webhooks/​invitation-accepted.yaml Removes the not-yet-emitted notice.
apps/​api/​api/​openapi/​components/​schemas/​errors/​inv-self_reject.yaml Generates the self-decline error schema.
apps/​api/​api/​openapi/​components/​schemas/​errors/​inv-inviter_not_admin.yaml Generates the inviter-authority error schema.
apps/​api/​api/​openapi/​components/​examples/​errors/​inv-self_reject.yaml Adds the generated self-decline error example.
apps/​api/​api/​openapi/​components/​examples/​errors/​inv-inviter_not_admin.yaml Adds the generated inviter-authority error example.
apps/​api/​api/​openapi/​bundled/​openapi.json Refreshes the bundled API contract.
apps/​api/​api/​cmd/​gen_openapi_errors/​main.go Accounts for adapter error translation during generation.
apps/​api/​api/​cmd/​gen_event_schemas/​main.go Marks redemption events as implemented.
.changeset/​invitations-redeem-api.md Adds customer-facing redemption release notes.

Review effort: Balanced

Comment thread apps/api/internal/api/invitation.go Resolved
Comment thread apps/api/internal/service/grant.go Resolved
…ip delegated grants

From review on #3025. EnsureUserGrant runs the same active, platform-homed
principal check as Create, and accept answers a user that is gone or no
longer active as auth.unauthorized. Delegated assignments sit outside the
unique binding the write targets, so they no longer count as an identical
grant or get revoked as an expired one.

Refs #2853

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Capturing now before the transaction allows connection waits or retries to bypass invitation expiry checks, permitting expired invitations to be accepted or rejected with metadata cleared instead of returning 404.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread apps/api/internal/service/invitation.go Resolved
…lining an invitation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Invitations created by project-local administrators return an ID-only inviter despite available user details because creator resolution incorrectly uses the platform project instead of the creator’s home project.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity An invitation created by a project-local administrator returns an ID-only inviter, even when that…

apps/​api/​internal/​service/​invitation.go:304

An invitation created by a project-local administrator returns an ID-only inviter, even when that user still has a name or identifier. Creation permits these administrators, but ResolveUserRefs filters users to the supplied project, so the platform-project lookup excludes them. Resolve CreatedBy through GetResourceScope and use its home project, preserving the ID-only fallback for a missing creator while propagating storage errors.

1 resolved since last review

Review effort: Balanced

@vitorbari

Copy link
Copy Markdown
Contributor Author

Superseded by #3072 and #3073.

@vitorbari vitorbari closed this Nov 13, 2026
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 13, 2026

This branch was successfully deployed

1 active deployment
Preview — 8f5f8b28 Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Invitations: look up, accept and decline by link

2 participants