Setting up Google OAuth
Use this when your project needs "Sign in with Google" - users authenticate with their Google account and your app receives an ID token / profile info.
Prerequisites
- Access to the WDCC tech Google account
- Your app's local dev URL (e.g.
http://localhost:3000) and any deployed domains
In Google Cloud Console
- Sign in to console.cloud.google.com using the WDCC tech account.
- From the project dropdown at the top, select your project. If the project doesn't exist yet, create a new one named after the project (e.g.
ayo). -
In the left nav, go to
APIs & Services->OAuth consent screenand complete the consent screen setup if it hasn't been done yet.Consent screen settings
- User type:
External - App name: project name (e.g.
Ayo) - User support email: WDCC tech email
- Developer contact: WDCC tech email
- Scopes: at minimum
userinfo.emailanduserinfo.profile
- User type:
-
Go to
APIs & Services->Credentials->Clients. If a client doesn't exist, clickCreate Credentials->OAuth client IDand selectWeb application. -
Configure the client with the following:
Authorised JavaScript Origins
Domains allowed to initiate OAuth from the browser. Add every origin the app runs on.
-
Save. Copy the
Client IDandClient secretshown.
In the Repository
-
Add the client credentials to your local
.env: -
For deployment, add the same values as fly secrets:
Troubleshooting
redirect_uri_mismatch error
The redirect URI your app sent doesn't exactly match one configured in the console. Check protocol (http vs https), port, and trailing slashes.
Access blocked: app not verified
Consent screen is in testing mode. Either add the user's email under Test users on the consent screen, or publish the app.
Google Service Accounts
Used for server-to-server access to Google APIs (e.g. reading/writing a Google Sheet) without a user signing in.
Found under IAM & Admin -> Service Accounts in the Google Cloud Console.
TODO
Write full setup once we actually use this in a project (key generation, scope grants, sharing the target Sheet/Drive resource with the service account email).