Skip to content

Conversation

@itsmeow
Copy link
Member

@itsmeow itsmeow commented Jun 24, 2025

Depends on BeeStation/BeeStation-Hornet#12927

Adds discord OAuth support. The game database user needs permission to insert into the SS13_session table.

Adds new private.yml options:

discord:
  client_id: #######
  client_secret: ################

For prod make sure to rebuild the container / run poetry install due to the updated dependencies.

The Discord OAuth2 application needs the identify scope and an authorized callback URI matching that of [api-url]/discord/callback

@Crossedfall
Copy link
Member

Curious how this works...

@Crossedfall Crossedfall requested a review from Copilot June 24, 2025 16:11

This comment was marked as outdated.

itsmeow and others added 2 commits June 24, 2025 12:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@itsmeow itsmeow marked this pull request as ready for review June 26, 2025 17:13
@Crossedfall Crossedfall requested a review from Copilot June 28, 2025 06:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Discord OAuth support for SS13 sessions, including token generation, storage, and UI for token retrieval.

  • Adds generate_random_session_token utility and a new Session model to store hashed tokens.
  • Implements Discord OAuth blueprint with callback handling and token display template.
  • Registers new configs, dependencies, and fixes a typo in the Patreon resource.

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/bapi/util.py Imported secrets and added generate_random_session_token
src/bapi/db.py Defined Session model with create_session method
src/bapi/blueprints/discord.py Added Discord OAuth routes (/auth, /callback)
src/bapi/templates/token.html Created token display template with auto-send script
src/bapi/templates/base.html New base layout template
src/bapi/resources/patreon.py Renamed PatreonOuathResource to PatreonOAuthResource
src/bapi/init.py Registered Discord blueprint and session DB binding
src/bapi/config/api.yml Added game-session-duration config key
pyproject.toml Added discord-oauth2-py dependency
Comments suppressed due to low confidence (2)

src/bapi/db.py:37

  • Consider adding unit tests for create_session, especially around invalid duration_days and hash storage, to ensure coverage for session token generation logic.
    def create_session(cls, ip, external_method, external_uid, external_display_name, duration_days):

src/bapi/db.py:51

  • The func namespace from SQLAlchemy is not imported, causing a NameError. Add from sqlalchemy import func.
            valid_until=func.date_add(func.now(), text(f"INTERVAL {duration_days} DAY")),

@Crossedfall Crossedfall merged commit 85ff51b into master Jun 28, 2025
4 checks passed
@Crossedfall Crossedfall deleted the discord-oauth branch June 28, 2025 18:47
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.

4 participants