Skip to content

Added OAuth-Based Discord Account Integration (Mirror)#62

Merged
yulmwu merged 3 commits into
mainfrom
feat/discord-integration
Jun 25, 2026
Merged

Added OAuth-Based Discord Account Integration (Mirror)#62
yulmwu merged 3 commits into
mainfrom
feat/discord-integration

Conversation

@yulmwu

@yulmwu yulmwu commented Jun 25, 2026

Copy link
Copy Markdown
Member

This PR introduces Discord account integration using OAuth. Once a user links their Discord account, they are automatically joined to a designated Discord server and assigned a role.

All Discord interactions are handled by a separate service independent of the main backend. The backend is responsible only for managing OAuth clients and storing account-linking information. The overall flow is shown below.

invitebot drawio

The following backend environment variables have been added:

# Discord Account Linking (OAuth2 on the backend; bot runs as a separate server)
DISCORD_ENABLED=true
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
# redirect_uri = the URL the BROWSER hits at the backend callback. Register it
# verbatim in the Discord Developer Portal (OAuth2 > Redirects; multiple allowed)
# and keep it identical here (scheme/host/port/path all matter).
#   - local direct:  http://localhost:8080/api/discord/callback
#   - production:    https://internal.swua.kr/wargame/api/discord/callback
DISCORD_REDIRECT_URI=http://localhost:8080/api/discord/callback
DISCORD_OAUTH_SCOPES=identify guilds.join
DISCORD_STATE_TTL=5m
DISCORD_OAUTH_TIMEOUT=10s
# Where to send the browser after the OAuth callback (frontend profile page).
#   - production: https://wargame.swua.kr/profile
DISCORD_SUCCESS_REDIRECT=http://localhost:3000/profile
# Invite link shown to users not yet in the guild (fallback button).
DISCORD_INVITE_URL=
# Auto-join the guild via guilds.join scope after linking.
DISCORD_AUTO_JOIN=true
# Connection to the separate Discord bot server.
DISCORD_BOT_BASE_URL=http://localhost:8083
DISCORD_BOT_SECRET=change-me
DISCORD_BOT_TIMEOUT=5s

DISCORD_CLIENT_ID and DISCORD_CLIENT_SECRET can be obtained from the Discord Developer Portal. You must also configure the corresponding Redirect URI.

In addition, DISCORD_BOT_SECRET must match the value used by the Invite Bot/Server. The following environment variables have been added for the Invite Bot/Server:

# Discord bot server configuration.
# The bot owns all Discord secrets; the wargame backend never sees these.

# HTTP server (internal API consumed by the wargame backend)
HTTP_ADDR=:8083

# Shared secret — MUST equal DISCORD_BOT_SECRET in the wargame backend .env
DISCORD_INTERNAL_SECRET=change-me

# Discord application / bot
DISCORD_BOT_TOKEN=
DISCORD_GUILD_ID=
DISCORD_VERIFIED_ROLE_ID=

# Optional
DISCORD_AUDIT_REASON=External site verification

Likewise, the bot token, guild ID, and role ID should be obtained from the Discord Developer Portal and configured appropriately for your environment.

Warning

The backend server and the Invite Bot/Server are intentionally separated due to bot sharding concerns. The current implementation was not designed with a general distributed environment in mind, so the bot server should be deployed as a separate single instance. This architecture may be improved in the future.

For more details, please refer to the updated source code and documentation.

yulmwu and others added 3 commits June 24, 2026 10:01
* feat: add discord account integration feature

* feat: add discord account integration feature

* docs: add docs

* chore: applied suggestion

* test: add some config test coverage
Port the Discord account linking feature from wargame: backend OAuth2 flow,
discord_connections persistence, /api/discord/* endpoints, the invite-bot
client, migrations, docs, and config. Adds scripts/sync-invite-bot.sh to sync
the invite-bot subtree from wargame.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
git-subtree-dir: invite-bot
git-subtree-mainline: 84f17ca
git-subtree-split: faed51c
@yulmwu yulmwu self-assigned this Jun 25, 2026
@yulmwu yulmwu added the enhancement New feature or request label Jun 25, 2026

@yulmwu yulmwu left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This PR is a mirror of the PR specified in the description. Since SMCTF and N4U Wargame share nearly identical codebases, we will merge it immediately without performing additional code reviews on the already verified code.

@yulmwu yulmwu merged commit e739b0c into main Jun 25, 2026
2 checks passed
@yulmwu yulmwu deleted the feat/discord-integration branch June 25, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant