Class Act

Back to the shelf

HTML · Method · ASP.net

Credentials Google Authentication

HTML and JavaScript to wire up Google OAuth sign-in on an ASP.NET page.

Example

How to use Credentials Google Authentication:
Paste the markup into the page and open it in a browser.

Code

Must enter the url in Authorized Javascript Origins

https://console.cloud.google.com/apis/credentials

Here is a more detailed, step-by-step instruction you can give to a developer or include in your application's setup documentation for Google Authentication.

Google Authentication Setup Instructions

There are 5 steps to configure Google Authentication in the Google Cloud Console.

Step 1: Open Google Cloud Credentials

Open the following URL in your browser:

Google Cloud Console — Credentials

Sign in with your Google account.

Select an existing Google Cloud project or click New Project to create one.

Give the project a name, such as MyApplication.

Open the APIs & Services ? Credentials section.

Step 2: Configure the OAuth Consent Screen

Before creating credentials, configure the OAuth consent screen. Depending on the current Google Console interface, this may be under Google Auth Platform ? Branding.

Enter your application name.

Enter the support email address.

Enter the developer contact email address.

Configure the audience:

Internal: Only users within your Google Workspace organization, when eligible.

External: Users with Google accounts outside your organization.

If the application is in testing mode, add the Google accounts that need permission to sign in under Test users.

Save the configuration.

Step 3: Create OAuth Client Credentials

Navigate to Google Auth Platform ? Clients, or return to the Credentials page.

Click Create Client or Create Credentials ? OAuth client ID.

Select Web application as the application type.

Enter a name, such as MyApplication Web Client.

You will now configure two important URL sections.

Step 4: Configure Authorized JavaScript Origins

Under Authorized JavaScript origins, enter the base URL of your application.

For example, if your application runs locally:

Local development

https://localhost:44300

Local HTTP development, if applicable

http://localhost:5000

Production website

https://www.yourdomain.com

Important rules:

Enter the application's origin, not the Google Cloud Console URL.

An origin consists of the protocol, hostname, and optional port.

Do not include a page path, such as /Login.aspx.

The protocol, hostname, and port must match the origin from which your application runs.

Use HTTPS for production websites.

The URL https://console.cloud.google.com/apis/credentials is where you configure the credentials;
   it is not the URL you enter as your application's authorized JavaScript origin.

Step 5: Configure Authorized Redirect URIs

Under Authorized redirect URIs, enter the callback URL that Google should return the user to after authentication, if your application uses a redirect-based OAuth flow.

For example, an ASP.NET WebForms application might use:

https://www.yourdomain.com/GoogleCallback.aspx

Or, for local development:

https://localhost:44300/GoogleCallback.aspx

The actual callback URL depends on your authentication library and implementation. If you use Google's JavaScript Identity Services with a callback handled directly in JavaScript, you may not need a redirect URI for that flow.

Click Create or Save when the configuration is complete.

Google will provide an OAuth Client ID. Copy it into your application's configuration. Never expose a client secret in browser-side JavaScript.

How the authentication flow works

The user clicks Sign in with Google in your application.

Google displays its sign-in interface.

The user selects their Google account and approves the requested access.

Google returns a credential or redirects the user, depending on the authentication flow.

Your application validates the credential or authorization response.

Your application creates its own authenticated session or authentication cookie.

Security note: If Google returns an ID token, your server must validate its signature, issuer, audience, and expiration before trusting the user's identity. Do not rely solely on a client-side success response or an email address supplied by the browser.

If you're implementing this in ASP.NET WebForms with C# or VB.NET, the exact configuration depends on whether you're using Google's JavaScript Identity Services or server-side OpenID Connect.