Skip to content

Feat: Authenticate from CLI#230

Merged
S1ro1 merged 8 commits into
mainfrom
feat/api-auth
Apr 6, 2025
Merged

Feat: Authenticate from CLI#230
S1ro1 merged 8 commits into
mainfrom
feat/api-auth

Conversation

@S1ro1
Copy link
Copy Markdown
Member

@S1ro1 S1ro1 commented Apr 3, 2025

Enables authentication via discord oauth -> we set redirect url to our /auth/cli (we figure out a proper name later), each cli instance gets a unique cli_id generated which maps user to cli. This cli gets encoded into state of the oauth2 redirect and sent to the server's auth url (/auth/cli).
Server then calls discord api to get user data, and inserts it into the database table, mapping the cli_id to the user_id.

To ban a user, we just ban based on discord username/user_id, this then doesn't allow them to auth via cli either. (NOT IMPLEMENTED YET)

This will then need a followup pr making each route also accept cli_id in the params.

Also possible update is to only use global discord names for the leaderboard, we should unify that (will tackle in another PR as well)

Makes heavy use of extra env vars (I'm not a fan of this), but they don't touch existing code at all so it's w.e.

@S1ro1 S1ro1 changed the title WIP: Authenticate from CLI Feat: Authenticate from CLI Apr 3, 2025
@S1ro1 S1ro1 marked this pull request as ready for review April 3, 2025 21:34
@S1ro1 S1ro1 requested review from b9r5, Copilot, msaroufim and ngc92 April 3, 2025 21:34
Copy link
Copy Markdown
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.

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

Comment thread src/discord-cluster-manager/api/main.py Outdated
Comment thread src/discord-cluster-manager/env.py Outdated
S1ro1 and others added 2 commits April 3, 2025 23:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread src/discord-cluster-manager/api/main.py Outdated
user_id = user_json.get("id")
user_name = user_json.get("username")

if not state:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

state is already checked at the top of the function

except psycopg2.Error as e:
self.connection.rollback()
logger.exception("Could not create/update user %s from CLI.", user_id, exc_info=e)
raise KernelBotError(f"Could not create/update user {user_id} from CLI.") from e
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

KernelBotError is intended to convey error messages to the end user, not exposing any internal data (that we'd log with logger).
AFAICS, this just triggers raise HTTPException(status_code=400, detail="Failed to create user"), so just re-raising the psycopg2 error would be fine here?

@S1ro1 S1ro1 mentioned this pull request Apr 3, 2025
@S1ro1 S1ro1 merged commit 92aa275 into main Apr 6, 2025
3 checks passed
@S1ro1 S1ro1 deleted the feat/api-auth branch April 6, 2025 17:00
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.

3 participants