Skip to content

Add Discord integration (OAuth flow + UI)#558

Merged
RSO merged 8 commits intomainfrom
feat/discord-integration
Feb 26, 2026
Merged

Add Discord integration (OAuth flow + UI)#558
RSO merged 8 commits intomainfrom
feat/discord-integration

Conversation

@RSO
Copy link
Contributor

@RSO RSO commented Feb 25, 2026

Summary

This PR adds the basic scaffolding for adding a Discord OAuth integration to the User/Organization level. It mostly works the same as our Slack integration and is heavily based on it.

CleanShot.2026-02-25.at.14.33.13.mp4

Add Discord as a new platform integration following the same architecture
as the existing Slack integration. This includes the OAuth2 flow for adding
the bot to a Discord server, storing guild information in the shared
platform_integrations table, and full frontend UI for both personal and
organization-level integrations.

Bot implementation will follow in a subsequent PR.
@RSO RSO requested review from a team and markijbema February 25, 2026 13:34
@RSO RSO marked this pull request as ready for review February 25, 2026 13:35
@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Feb 25, 2026

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/app/api/integrations/discord/callback/route.ts 36 Redirecting unauthenticated callback requests straight to sign-in drops OAuth code/state, making install flow non-recoverable after session expiry.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
N/A N/A None.
Files Reviewed (18 files)
  • src/app/(app)/integrations/IntegrationsPageClient.tsx - 0 issues
  • src/app/(app)/integrations/discord/page.tsx - 0 issues
  • src/app/(app)/organizations/[id]/integrations/IntegrationsPageClient.tsx - 0 issues
  • src/app/(app)/organizations/[id]/integrations/discord/page.tsx - 0 issues
  • src/app/api/integrations/discord/callback/route.ts - 1 issue
  • src/components/integrations/DiscordContext.tsx - 0 issues
  • src/components/integrations/DiscordIntegrationDetails.tsx - 0 new issues
  • src/components/integrations/OrgDiscordProvider.tsx - 0 new issues
  • src/components/integrations/UserDiscordProvider.tsx - 0 new issues
  • src/lib/config.server.ts - 0 issues
  • src/lib/integrations/core/constants.ts - 0 issues
  • src/lib/integrations/discord-service.ts - 0 new issues
  • src/lib/integrations/oauth-state.ts - 0 new issues
  • src/lib/integrations/platform-definitions.ts - 0 issues
  • src/routers/discord-router.ts - 0 new issues
  • src/routers/organizations/organization-discord-router.ts - 0 new issues
  • src/routers/organizations/organization-router.ts - 0 issues
  • src/routers/root-router.ts - 0 issues

Fix these issues in Kilo Cloud

@RSO RSO changed the title Add Discord integration (OAuth flow + UI) Add Discord integration (OAuth flow, UI, and bot with Gateway WebSocket) Feb 25, 2026
@RSO RSO force-pushed the feat/discord-integration branch from d907a68 to 0b8e8ed Compare February 25, 2026 14:08
@RSO RSO changed the title Add Discord integration (OAuth flow, UI, and bot with Gateway WebSocket) Add Discord integration (OAuth flow + UI) Feb 25, 2026
@marius-kilocode
Copy link
Contributor

Unblocking, please at least verify the OAuth comments and the authentication.

The state parameter was a plain, guessable string (user_id/org_id),
allowing authorization code injection attacks. Sign it with
HMAC-SHA256 using NEXTAUTH_SECRET and embed the initiating user's ID
so the callback can verify the flow wasn't tampered with.
The signed OAuth state payload previously only contained { owner, uid },
making it deterministic and valid indefinitely. A leaked state token
(via logs, referrer headers, browser history) could be replayed at any
time by the same authenticated user context.

Add an issued-at timestamp (iat) with a 10-minute TTL and a 128-bit
random nonce to each state token. Verification now rejects tokens that
are expired, have future timestamps, or lack the new fields.
@RSO RSO merged commit cdd939b into main Feb 26, 2026
12 checks passed
@RSO RSO deleted the feat/discord-integration branch February 26, 2026 12:21
// 1. Verify user authentication
const { user, authFailedResponse } = await getUserFromAuth({ adminOnly: false });
if (authFailedResponse) {
return NextResponse.redirect(new URL('/users/sign_in', APP_URL));
Copy link
Contributor

Choose a reason for hiding this comment

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

WARNING: Auth redirect drops OAuth callback context, causing non-recoverable install failures for signed-out users.

When getUserFromAuth fails, this redirects to /users/sign_in without preserving the current callback URL (code/state). If a user’s session expires between initiating OAuth and callback, they authenticate successfully but cannot resume the install because the authorization code/state are lost. Consider redirecting to sign-in with a callbackPath back to this callback URL so the flow can continue safely.

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.

2 participants