Google Authentication
This guide explains how to set up Google OAuth authentication for the U/=22A8 application.
Prerequisites
- A Google account
- Access to the Google Cloud Console
Step 1: Create a Google Cloud Project
- Go to the Google Cloud Console
- Click on the project dropdown at the top of the page
- Click New Project
- Enter a project name (e.g., "U/=22A8")
- Click Create
Step 2: Configure the OAuth Consent Screen
- In the left sidebar, navigate to APIs & Services > OAuth consent screen
- Select External as the user type (unless you have a Google Workspace organization)
- Click Create
- Fill in the required fields:
- App name: U/=22A8
- User support email: Your email address
- Developer contact information: Your email address
- Click Save and Continue
- On the Scopes page, click Add or Remove Scopes
- Select the following scopes:
openidemailprofile
- Click Update and then Save and Continue
- Skip the Test users section (click Save and Continue)
- Review and click Back to Dashboard
Step 3: Create OAuth Credentials
- In the left sidebar, navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Web application as the application type
- Enter a name (e.g., "U/=22A8 Web Client")
- Under Authorized JavaScript origins, add:
http://localhost:3000(for development)- Your production domain (e.g.,
https://example.com)
- Under Authorized redirect URIs, add:
http://localhost:3000/api/auth/callback/google(for development)- Your production callback URL (e.g.,
https://example.com/api/auth/callback/google)
- Click Create
- Copy the Client ID and Client Secret
Step 4: Configure Environment Variables
Add the following to your .env.local file:
AUTH_GOOGLE_ID="your-client-id.apps.googleusercontent.com"
AUTH_GOOGLE_SECRET="your-client-secret"
Step 5: Test the Integration
- Start the development server:
nx dev web
- Navigate to
http://localhost:3000 - Click the Sign In button
- Select Continue with Google
- You should be redirected to Google's OAuth flow
Customizing Scopes
To request additional Google API scopes, modify the Google provider configuration in auth.ts:
Google({
clientId: process.env.AUTH_GOOGLE_ID,
clientSecret: process.env.AUTH_GOOGLE_SECRET,
authorization: {
params: {
scope: "openid email profile https://www.googleapis.com/auth/calendar.readonly",
},
},
}),
Production Checklist
Before deploying to production:
- Publish your OAuth consent screen (if using external user type)
- Add your production domain to authorized origins and redirect URIs
- Consider setting up domain verification for enhanced security
- Review and limit the scopes to only what's necessary
Troubleshooting
"Access blocked: This app's request is invalid"
- Ensure the redirect URI exactly matches what's configured in Google Cloud Console
- Check for trailing slashes in the redirect URI
"Error 400: redirect_uri_mismatch"
- The redirect URI in your request doesn't match the authorized redirect URIs
- For development, use
http://localhost:3000/api/auth/callback/google
"This app isn't verified"
- This is normal during development with an unpublished OAuth consent screen
- Click Advanced > Go to [App Name] (unsafe) to continue testing
- For production, submit your app for Google verification