Feat: Authenticate from CLI#230
Merged
Merged
Conversation
ngc92
reviewed
Apr 3, 2025
| user_id = user_json.get("id") | ||
| user_name = user_json.get("username") | ||
|
|
||
| if not state: |
Collaborator
There was a problem hiding this comment.
state is already checked at the top of the function
ngc92
reviewed
Apr 3, 2025
| 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 |
Collaborator
There was a problem hiding this comment.
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?
Merged
ngc92
approved these changes
Apr 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 uniquecli_idgenerated which maps user to cli. This cli gets encoded intostateof 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.