Google OAuth Setup
Configure Google OAuth for authentication in your AI SaaS platform
Google OAuth Setup
Now that you have deployed your core infrastructure and set up Stripe, it's time to configure Google OAuth for authentication. This will allow users to sign in with their Google accounts, providing a smoother onboarding experience.
Creating a Google Cloud Project
Sign In to Google Cloud Console
- Go to the Google Cloud Console
- Sign in with your Google account
Create a New Project
- Click on the "Select project" dropdown at the top left of the page
- Click "New Project" in the popup window (located at the top right)
- Enter a project name (e.g., "AI SaaS Platform")
- Click "Create"
- Once the project is created, click on the "Select project" dropdown again
- Select your newly created project from the list
Configuring OAuth Consent Screen
Access OAuth Consent Screen
- In the Google Cloud Console, with your project selected, click on the navigation menu (three horizontal lines in the top left)
- Navigate to "APIs & Services" > "OAuth consent screen"
- You'll see a message: "Google Auth Platform not configured yet"
- Click the "Get started" button
Configure App Information
- App name: Enter your application name
- User support email: Enter your email address
- Click "Next"
Set Audience Type
- Select "External" as the user type
- Click "Next"
Add Developer Contact Information
- Developer contact information: Enter your email address
- Click "Next"
Complete Setup
- Check "I agree to the Google API Services: User Data Policy."
- Click "Continue"
- Click "Create" to finalize the consent screen setup
Creating OAuth Client ID
Create Client ID
On the OAuth consent screen overview page, you'll see:
- A message saying "You haven't configured any OAuth clients for this project yet."
- Click the "Create OAuth client" button
Configure Client
- Application type: Select "Web application"
- Name: Enter a name for your client (this is only visible in the console, not to end users)
Add Authorized JavaScript Origins
First, retrieve your Amplify app URL, from your CDK directory run:
Then, configure the authorized origins:
- Click "Add URI" under Authorized JavaScript origins
- Add your Amplify domain:
https://dev.xxxxxxxxxxxx.amplifyapp.com
(use the actual URL you retrieved) - Click "Add URI" again and add
http://localhost:3000
for local development
Add Authorized Redirect URIs
First, retrieve your complete Cognito callback URL, from your CDK directory run:
Then, add the complete callback URL to the authorized redirect URIs:
- Click "Add URI" under Authorized redirect URIs
- Paste the complete Cognito callback URL you retrieved
The callback URL is constructed by taking the Cognito domain URL and appending /oauth2/idpresponse
, which is the standard path for the OAuth response handling in AWS Cognito. This exact URL is critical for the OAuth flow to work correctly, as Google will redirect users to this URL after authentication.
Create and Save Credentials
- Click "Create"
- A popup will appear with your credentials:
- Client ID (looks like:
xxxxxxx.apps.googleusercontent.com
) - Client Secret
- Client ID (looks like:
- Copy both values or download the JSON file
If you forget to save these credentials, you can always access them later:
- Go to "APIs & Services" > "Credentials"
- Find your OAuth 2.0 Client ID in the list and click on it
- You can view the Client ID and Client Secret on this page
Still, it's good practice to save them securely after creation.
Updating Your Deployment with Google OAuth Credentials
Update Environment Variables
Navigate to the CDK directory (if you're not already there) and update your .env
file with the Google OAuth variables:
Open your .env
file and update these values:
Replace the placeholder values with your actual Google OAuth Client ID and Secret.
Redeploy Your Infrastructure
After updating the environment variables, redeploy your infrastructure to apply the changes:
This deployment will update your Cognito User Pool to enable Google OAuth authentication.
Verifying Google OAuth Integration
After completing the Google OAuth setup and redeploying, it's important to verify that the social authentication is working correctly:
Access Your Application
Navigate to your application URL (the Amplify app URL you retrieved earlier).
Wait for the Amplify build to complete before testing. You can check the build status in the AWS Amplify console.
Test Google Sign-In
- Click on "Sign In" or navigate to the login page
- You should see a "Sign in with Google" button alongside the email/password form
- Click the "Sign in with Google" button
- You should be redirected to Google's authentication page
- Sign in with your Google account
- After authenticating, you should be redirected back to your application and logged in
Verify User Creation
After signing in with Google for the first time:
- Check that you're successfully logged in
- Verify that your profile information (like name and email) is correctly populated
- Navigate to the dashboard to confirm you have access to all features
Check Cognito User Pool
Verify that the user was created in your Cognito User Pool:
- Go to the AWS Console
- Navigate to Amazon Cognito > User Pools
- Select your user pool (it will have your app name as a prefix)
- Click on "Users"
- Verify that a user with your Google email address exists
- Note that the user should have "Google" listed as an identity provider
Next Steps
Now that you have successfully set up and verified Google OAuth authentication, proceed to AWS Bedrock Setup to enable the image generation capabilities in your AI SaaS platform.