Google OIDC Setup
OIDC Setup (Google) for Expertiza Backend
This guide explains how to configure Google Cloud Console so this Rails app can authenticate with OIDC and access a user's email.
Note: Current provider config is in config/oidc_providers.yml under providers.google-ncsu.
1: Prerequisites
- Google account with access to Google Cloud Console
- The full stack to be running
- Vite/React Frontend
- Ruby on Rails API (This project)
- MySQL database
- Redis (currently used for caching, though not currently use for offloading temporary OIDC tokens)
- The redirect URI that matches the app config exactly
- Local example:
http://localhost:3000/auth/callback - This value should come from
GOOG_REDIRECT_URIfor the Rails API
- Local example:
2: Create or select a Google Cloud project
- Open Google Cloud Console.
- Create a new project (or select an existing one).
- Make sure the selected project is the one you want for OIDC.
- If you create a new project but had existing projects, you may need to select your new project.
- Google will sometimes select the previous project you used rather than the newly created project.
3: Configure OAuth consent screen
- Go to Explore and Enable APIs: APIs Dashboard
- Click the OAuth consent screen in the side navigation.
- Click "Get Started" and fill in the required app details
- App name
- Example: NCSU SSO
- Support email
- For local dev use your email
- Developer contact email
- For local dev use your email
- App name
- Choose External (unless you've been instructed otherwise for test/production).
- Agree to the API terms and create.
Configure Scopes
- Select
Data Accessin the left navigation. - Click Add/Remove Scopes.
- At a minimum we need to add:
openidemail, displays as.../auth/userinfo.emailprofile, displays as.../auth/userinfo.profile
- At a minimum we need to add:
Why not "email scope only"
For OIDC login, Google should receive openid email.
emailgives access to the email claim.openidis required for an OIDC ID token.
If you send only email without openid, OIDC token validation will fail.
4: Add test users (if app is in Testing mode)
- Click
Audiencein the side navigation. - Go to the
Test Userssection. - Click
Add users. - Enter your NCSU email, press enter, and save.
5: Create OAuth client credentials
- Select
Clientsfrom the side navigation. - Click
Create Clientat the top of the screen. - Application type: Web application.
- Name it "Expertiza SSO".
- Append Dev or Test to the name if necessary.
- Add Authorized redirect URI:
- Enter the frontend auth callback URL.
- Local Dev should have the redirect URI from Step 1.
- Enter the frontend auth callback URL.
- Click Save.
Important: This is the only time you will see the secret.
The credential window gives the option to download the ID and secret as JSON.
If this is for production, download the JSON and save it to a secure key vault for future use/reference.
- Copy:
- Client ID
- Client Secret
6: Configure app environment variables
Set these environment variables for the Rails application:
GOOG_CLIENT_IDGOOG_CLIENT_SECRETGOOG_REDIRECT_URI
Examples:
- PowerShell
$env:GOOG_CLIENT_ID="<app_client_id>"
$env:GOOG_CLIENT_SECRET="<app_client_secret>"
$env:GOOG_REDIRECT_URI="<http_frontend_baseurl>/auth/callback"
- bash / WSL
export GOOG_CLIENT_ID="<app_client_id>"
export GOOG_CLIENT_SECRET="<app_client_secret>"
export GOOG_REDIRECT_URI="<http_frontend_baseurl>/auth/callback"
If you use Docker Compose:
- You can either add the env settings directly in Compose environment settings.
- If you use this option, do not commit the Compose file with secrets.
- You can create a
.envfile and have Docker Compose reference it. Then put the OIDC info in your env file and redeploy with Docker Compose.
Docker .env example:
GOOG_CLIENT_ID='xxxxxxx.apps.googleusercontent.com'
GOOG_CLIENT_SECRET='XXXXXX-xxxxxxxxxxxxxxxxxxxxxxxxx'
GOOG_REDIRECT_URI='http://localhost:3000/auth/callback'
7: Verify provider config
config/oidc_providers.yml should match:
issuer: https://accounts.google.comclient_id: <%= ENV['GOOG_CLIENT_ID'] %>client_secret: <%= ENV['GOOG_CLIENT_SECRET'] %>redirect_uri: <%= ENV['GOOG_REDIRECT_URI'] %>
scopes is currently optional in this repo.
If omitted, OidcConfig.scopes_for defaults to:
openid email profile
If you want to restrict to email-focused login:
- Keep
openid email - Remove
profilefrom the actual scope source:- If the provider defines
scopesinconfig/oidc_providers.yml, set it toopenid email - If
scopesis omitted, the fallback comes fromOidcConfig.scopes_for, so update that default if you want repo-wide behavior withoutprofile
- If the provider defines
8: Quick runtime validation
- Start the backend.
- Call provider list endpoint:
GET /auth/providers
Expected result: includes google-ncsu.
If you get an empty array, confirm env vars are present in the running process.
9: Common issues
Empty /auth/providers
- Usually means one or more required provider fields are blank after ERB eval.
- Most often
GOOG_CLIENT_ID,GOOG_CLIENT_SECRET, orGOOG_REDIRECT_URIis missing. - Error reporting can be found in the Rails logs.
Redirect URI mismatch
- Google and app must match exactly (scheme, host, port, path).
invalid_client
- Wrong client ID/secret pair, or credentials from a different project.
Consent screen / test user errors
- Add your account as test user if app is in Testing mode.
10: Production notes
- Use production redirect URI (HTTPS).
- Store secrets in a secure secret manager or deployment environment.
- Do not commit credentials to git.