Skip to content

Discord chat: connect a forum account from Discord's Linked Roles menu - #452

Merged
TripleU613 merged 2 commits into
mainfrom
discord-chat/linked-roles
Nov 25, 2026
Merged

TripleU613 merged 2 commits into
mainfrom
discord-chat/linked-roles

Conversation

@TripleU613

Copy link
Copy Markdown
Owner

Serves the Linked Roles Verification URL at /discord-chat/link (default off, discord_chat_linked_roles_enabled).

Flow: server menu → Linked Roles → sign in here → approve on Discord → accounts linked (same fields core stores), role connection recorded, sync enqueued.

  • Why not core's connect: its OAuth scopes are fixed; Linked Roles needs role_connections.write.
  • Stricter than core on conflicts: refuses a Discord account linked to someone else, and a forum account already linked to another Discord account (core would move it).
  • OAuth state in the server session, 10 min, single use.
  • The linked role grants nothing; docs warn not to put the requirement on the member role (a suspended member could re-claim it).

Specs: login redirect, authorize redirect, link + role-connection + sync, bad/reused state, both conflicts, signed-out callback links nothing, cancel links nothing, setting off → 404; metadata registration job.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs

discord_chat_linked_roles_enabled serves Discord's Linked Roles
Verification URL at /discord-chat/link. A member starts from the server
menu, signs in here if needed, approves the app on Discord, and comes back
connected: the Discord account is linked to their forum account the way the
Discord login links it, the role connection is recorded, and the sync runs
straight away to give the roles the forum allows.

Core's Discord connect can't be reused because its OAuth request has fixed
scopes, and Linked Roles needs role_connections.write. This is stricter
than core on conflicts: a Discord account linked to another forum account,
or a forum account already linked to another Discord account, is refused
rather than moved. The OAuth state lives in the server session for ten
minutes and is single-use.

The linked role grants nothing itself; the docs and setting description say
to keep its requirement off the member role, since Discord lets people
claim linked roles from its menu and a suspended member could otherwise
claim their way back in. Turning the setting on registers the one yes/no
requirement with Discord. Off by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BUGDaR7qv2d8CuVp7UGSTs
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T19:43:05.773156Z 1b02ce5 PR opened
🔒 Security Review ✅ Completed 2026-11-25T19:46:24.611825Z 1b02ce5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b02ce5864

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +63 to +64
if name.to_sym == :discord_chat_linked_roles_enabled
Jobs.enqueue(:discord_chat_register_linked_role)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Register linked-role metadata after configuration changes

If discord_chat_linked_roles_enabled is enabled before the bot token or guild ID is configured, this event is skipped by the preceding configured? guard; setting the missing prerequisite later only enqueues member sync because this condition matches exclusively on the linked-role setting. The metadata is therefore never registered, and Linked Roles remains unusable until an administrator toggles the setting off and on again. Trigger registration when any prerequisite becomes valid, not only when this single setting changes.

Useful? React with 👍 / 👎.

Comment on lines +101 to +103
rescue Api::Error => e
Rails.logger.warn("#{DiscourseDiscordChat::LOG_TAG} link: #{e.message}")
finish("Discord didn't answer. Try again in a minute.", 502)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle Discord transport failures in the callback

If Discord is unreachable, DNS fails, or either Net::HTTP timeout expires, Net::HTTP.start raises exceptions such as SocketError, Net::OpenTimeout, or Net::ReadTimeout, none of which inherit from Api::Error. Those expected outage cases therefore escape this rescue and turn the OAuth callback into an internal-server-error response instead of the intended retryable 502 message.

Useful? React with 👍 / 👎.

@TripleU613
TripleU613 merged commit cdff58a into main Nov 25, 2026
8 checks passed
@TripleU613
TripleU613 deleted the discord-chat/linked-roles branch November 25, 2026 19:55
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.

1 participant