Google OAuth
Implementing Google OAuth with LucidAuth
Obtaining Google OAuth 2.0 Credentials
Follow the steps below to create a project in the Google Cloud console and obtain OAuth 2.0 credentials, which authenticate your application to Google’s OAuth 2.0 server.
Create a Project
- Go to the Google Cloud Console.
- On the main navigation bar at the top, to the left of the search box, you’ll see the project selector. Click it to open a dialog listing all your projects. In the dialog click New project.
- Enter a project name and click Create. Once the project is created, click Select project. The project’s name should appear in the project selector.
- Next, click the hamburger menu on the top-left corner of the page to open the sidebar navigation, then navigate to APIs & services > OAuth consent screen.
OAuth consent screen
- On the OAuth overview page, click Get started.
- Under App information, enter your app name and user support email, then click Next.
- Select External as the audience type (This setting makes your project accessible to anyone with a Google account.), then click Next.
- Under Contact Information, enter your email address, then click Next.
- Select the checkbox labeled I agree to the Google API services user data policy, then click Continue.
- Click Create.
- You should see a toast notification with the message OAuth configuration created.
OAuth credentials
-
Click the hamburger menu in the top-left corner of the page to open the sidebar navigation, then navigate to APIs & services > Credentials.
-
On the Credentials page, click +Create credentials to open the dropdown menu. Click OAuth client ID.
-
Select Web application as the application type. Then, enter a name for your OAuth 2.0 client in the Name field. (This name is used only to identify the client in the console and is not shown to end users.)
-
Under Authorized JavaScript origins, click Add URI and enter
http://localhost:3000. This URI is the HTTP origin that hosts your web application. Note: When you deploy your app to production, you will need to come back here and add your live domain, e.g.,https://your-domain.com. -
Under Authorized redirect URIs, enter
http://localhost:3000/api/auth/callback/google. This URI is the endpoint in your application where the Google OAuth server will send responses to your authentication requests. Note: When you deploy your app to production, you will need to come back here and add your live callback URL, e.g.,https://your-domain.com/api/auth/callback/google.Note
The authorized redirect URI must exactly match
http://localhost:3000/api/auth/callback/google. LucidAuth requires this specific endpoint to verify and process the authorization code sent from the Google authorization server. -
Click Create.
-
After the OAuth client is created, a dialog appears with the title OAuth client created. In the dialog you’ll see both the Client ID and Client secret details. Copy both and store them securely; you'll need these credentials in the next section when setting up environment variables.