feat(mcp): /mcp/issue signs in with Forgejo and files as the person #5
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/forgejo-signin"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
/mcp/issuenow signs people in with their account on git.magicbean.dev, not Discord, and files the report with their own login, as if they had used the web form. This is the design indocs/architecture/index.md, built, plus one change to it: the AI never holds a forge token.Stacked on #4 (
docs/explanation): merging this brings #4's docs in.The gate
A second authorization server. It is at
/oauth/forgejo: issuer<gate>/oauth/forgejo, metadata at/.well-known/oauth-authorization-server/oauth/forgejo, endpoints/oauth/forgejo/{register,authorize,callback,token,revoke}. A route's resource metadata names its rule's server, so a client discovers which one to sign in with.Policy. A rule gets
"login": "forgejo", which gives theforgerole. The new modeidentity-and-tokenhands the service the identity token and, inX-Forge-Token, the person's forge token. The identity token holds that token's digest (cred), so a service takes the forge token only with the identity it was checked for. Validation refuses Discord roles on a Forgejo rule, theforgerole on a Discord rule, and a Discord token handed on.Sessions, not forge tokens. The client may be a public AI, run by its provider. The gate keeps the forge's tokens and answers the login with a random session token of its own:
FORGEJO_SESSION_SECONDSat most (default 3600), less if the forge's token expires first./oauth/forgejo/revoke), with the session token or the forge token.A forge token a client sends itself is refused.
Settings:
FORGEJO_URL,FORGEJO_CLIENT_ID,FORGEJO_CLIENT_SECRET,FORGEJO_SCOPES(defaultread:user read:repository write:issue). The gate refuses to start when the policy uses Forgejo and the app isn't set.Unchanged: the Discord sign-in,
/mcp/grafanaand every existing gate test.mcp-issue
forgejo.Clientwithout a token of its own (forgejo.WithToken). Forgejo's own permissions, bans and blocks apply.issues.ErrForbidden, and the AI gets it back as a refusal it can act on, not "the forge could not be reached".LABEL_BOT_TOKEN, through the newissues.Labeler). A labelling failure is logged; the issue stays open.create_issueorcomment_on_issue, mcp-issue revokes the session at the gate (REVOKE_URL), so the token the AI holds is dead. The tool's answer and the instructions tell the AI: one report per sign-in.ISSUE_BOT_TOKENis gone. The credit line under a report no longer names a Discord user; the forge shows the author.⚠️ What clients see changes
/mcp/issue: it was never deployed, but its contract changes. It takes theforgerole, notmember, and needsX-Forge-Token.X(Discord)" becomes "Sent through Longshot's issue assistant…". The compatibility tests are updated to match (report, mcp-issue, e2e).Tested
scripts/lint.sh: 0 issues.scripts/docs.sh --check: current.go test -race ./...passes, and coverage is at or above where it was in every package.go test -race -tags e2e ./test/e2e/passes. The real binaries run against a fake forge: discovery, the Forgejo login, a session (not the forge's tokens),/auth, the issue opened as the person, labelled by the bot, and the session over afterwards./authorizeredirecting to the forge's sign-in.To deploy (Bean-Ops, not in this PR)
https://api.magicbean.gmatte.xyz/oauth/forgejo/callback. Its id and secret go in a SOPS secret for the gate.{"prefix": "/mcp/issue", "login": "forgejo", "roles": ["forge"], "mode": "identity-and-token", "audience": "mcp-issue"}.X-Forge-Tokenin the/mcp/issueforwardAuth'sauthResponseHeaders, besideAuthorization.LABEL_BOT_TOKEN.deploy/mcp-issue.🤖 Generated with Claude Code