-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Add the ability to sign in with Google. The end goal is that the current registration and username/password system will be completely replaced (with the option to use the current username/password login only for accounts created before the new system was put in place).
-
Phase 1: Add ability to link google accounts to current pointercrate accounts. If I understand the high level overview that google gives on https://developers.google.com/identity/gsi/web/guides/integrate, it actually sounds quite simple
-
Add a
google_account_idcolumn to thememberstable -
Add a "Sign-In With Google" button to the account landing page (https://pointercrate.com/account)
-
Most of the complicated oauth stuff is handled by google. We can use the HTML API. The flow here is
- The user clicks the button, and goes through whatever Google does to log you in
- Google calls a JavaScript function in the pointercrate frontend, and passes it a JWT for the Google Account that just logged in (let's refer to it as GJWT, and to pointercrate's JWT that identifies the pointercrate account currently signed in as PJWT)
- Our JS handler does a
POSTto a new pointercrate API (say/api/v1/auth/google/link) containing the GJWT and authorizing with the PJWT. - The backend verifies the GJWT. If it is valid, get the currently logged in pointercrate account from the PJWT, and update this account's entry in the
memberstable by setting thegoogle_account_idto thesubfield of the GJWT.
-
-
Phase 2: Add ability to actually log in with google
- We add a "Sign In With Google" button to the login page (https://pointercrate.com/login)
- The flow will be very similar to above, however the pointercrate endpoint (say
/api/v1/auth/google/login) handling log-ins with Google will query the members table for the account that has the received Google JWT's sub field (after validating, ofc!), and return a PJWT for that account on success (still, a lot of code can probably be shared with step 1. - let's cross that bridge when we get to it though)
-
Phase 3: Add ability to create new accounts through Google Sign Up - This one might actually be the trickiest one, funnily enough
-
We deprecate the existing registration endpoint (
/api/v1/auth/register). I think it's fine to just have it start returning some error unconditionally. -
When creating a new account through google sign-in, we'll need to deal with two problems (after doing the same OAuth dance as above):
- How to fill in the new account's user name?
- dealing with the fact that no passwords exist for these accounts.
The latter is a problem because the JWT pointercrate creates are signed using a combination of the server's secret and the random salt used when hashing the account's password (which, yeah, no idea what 16 y/o me was thinking here). So that'll have to get fixed up. I guess just depending on the server's secret will be enough, but we need to make sure that we only change this for accounts that were created through the google sign-up option, old accounts should continue doing whatever we are doing right now.
The former, we can fix by simply dropping the entire username concept. Accounts created through Google Sign-Up with have the username field set to
null, and theirdisplay_namefield set to the name of the google account (we get this information from the GJWT). Reason for this being that this is easier than providing some bizarre "username initially set to name of google account, but you can change it once in case you don't want to have the google name public" functionality. Currently pointercrate only uses the username for "legacy" login (which wont be possible for these accounts anyway), and when rendering the account as part of the claim verification system, and when you're a List Mod. For the latter reasons, we should make display name mandatory for these accounts (they can stay optional for legacy accounts). -
We'll also need to take passwordless-ness into account when rendering the UI (e.g. there should be no "change password button"), and when doing various PATCH requests (e.g. no programmatic password changes via
PATCH /api/v1/auth/me)
-
We won't support changing the google account associated with a pointercrate account (at least for now, although I guess a lot of the code from Phase 1 could be reused to implement this should it ever be needed).
- Phase 4: Automatic Claim Verification via YouTube API. This is the most open-ended one yet. I think we can either request a GJWT that allows us read-only access to that google account's public YouTube videos (in which case we need to store not just the Google Account Id, but the entire GJWT, and also implement some refresh functionality, which sounds nasty), or we simply implement a second OAuth flow during player verification (probably simpler). Here, some research probably needs to be done. Either way though, what we want to have is the following system:
- If a pointercrate account initiates a claim on a player, cross-reference the YouTube videos of records of the claimed player with the YouTube Channel of the Google Account associated with the Pointercrate Account.
- If all record videos are from the YouTube channel of the account initiating the claim, auto-approve the claim (maybe we can have some sort of threshold based system here, and we'll have to think about very old records without videos/deleted videos, but I'd hope those are edge-cases that can be manually reviewed using the current system).