Table of Contents


Implement Google Oauth2 in ASP.NET Core

Step 1: Create New Asp.net Core Project

Open a visual studio, Create new project named ” Asp.Net core web application” or name of your choice, example “OauthGoogle”

Step 2: Create database with code-first approach

When we select the template, which has been given in step 1 there is already Identity class added to project, and now we have to create Database and their tables base on that identity class.

Before running the application, we need to apply migrations to our app

Go to Tools >> NuGet Package Manager >> Package Manager Console.

Enter ”Update-Database” and hit enter key . This will create identity tables.

Step 3: Get the application URL to use at Google App

Now run your application will open the below screen.

Note the URL from the browser address bar. In this case, the URL is https://localhost:44360/ We need this URL to configure our Google app which we will be doing in our next step.

Step 4: Create a Google App

Navigate to https://console.developers.google.com and login using your Google account. If you do not have a Google account, you need to create one. You cannot proceed without a Google account.

After clicking on the Create Project button then shown a popup window for Project name, where you can specify the name of the project where you can use the google API.

Step 5: Your project Create successfully and you will be redirected to API Library page

After that we need to Enable “Google+API” so we can search in search box and click on the highlighted “Google+API”

And Enable this Google+ API.

Step 6: Create Credentials

Once Goolge+API is enabled it will automatically redirect to API home page. From the API Home page Click on the “Create credentials” button on the right side of the page to configure the secrets for your API.

You will see an “Add credentials to your project” fill the following field

Step 7: Create External OAuth Consent Screen

Now going to “OAuth consent screen” at the left side on the page and choose the External option and click on the create button

Step 8: Create Client Id and Client Secret

Select the “Credentials” menu from the left site and after that click on the "+Create credentials" on the highlighted in the snapshot and select OAuth Client Id options.

Step 9: Create Application Name and Redirect URI

After click on the OAuth enter the “Application name, Authorized Javascript Origins(if required) and Authorized redirect URIs” and click on the Create button

Click on the Create button you can see your “client Id and Client Secret” has been created.

Step 10: Add Client Id and Secret in Visual Studio Project

Now go to project and right click on the project and go to Manage User Secrets, Which Create the secrets.json.

Step 11: Setup the secrets.json and startup.cs

A secrets.json file will open put the following code in it

Now open startup.cs file and put the following code into ConfigureServices method

Step 12: Save and Run Application

After clicking on the Login, you see Google button and click on this

After that enter you Email account

Once you logged in with Gmail Id then you will successfully authenticate with Google.

Step 13: Goto SQL Server Management

Now go to SQL Server Management Studio and let’s check our database Name “OAuthFacebook” and “Tables”.

Now go to “AspNetUserLogins” and execute. We can see the following detail about Google.

Also execute “AspNetUsers” table and see users are login.

That is it!

Latest from Prishusoft

Azure AD Auth with MSAL in Angular and ASP.NET Core API
Web Development

Azure AD Auth with MSAL in Angular and ASP.NET Core API

Learn how to implement Azure AD authentication in your Angular app using MSAL and connect it securely with ASP.NET Core Web API. Step-by-step setup included.

Oct 20, 2020
How to Implement Okta Authentication in Angular Apps
Web Development

How to Implement Okta Authentication in Angular Apps

Learn how to integrate Okta authentication in Angular using OAuth 2.0 and OIDC. Step-by-step guide for secure login, token handling, and route protection.angular

Aug 05, 2020
How to Implement Google OAuth2 Authentication in ASP.NET Core
Web Development

How to Implement Google OAuth2 Authentication in ASP.NET Core

Step-by-step guide to implement Google OAuth2 authentication in ASP.NET Core. Secure your app with Google sign-in, token validation, and user claims.

Jul 27, 2020
How to Implement Facebook OAuth2 Login in ASP.NET Core
Web Development

How to Implement Facebook OAuth2 Login in ASP.NET Core

Learn how to implement Facebook OAuth2 login in ASP.NET Core. Step-by-step guide to configure app ID, secret, and secure authentication with user claims.

Jul 20, 2020
Implement JWT Authentication in ASP.NET Core and Angular 8 – Part 1
Web Development

Implement JWT Authentication in ASP.NET Core and Angular 8 – Part 1

Learn how to implement JWT authentication using ASP.NET Core backend and Angular 8 frontend. Secure your app with token-based login in this step-by-step guide.

Jul 09, 2019
JWT Authentication in ASP.NET Core and Angular 8 – Part 2 Guide
Web Development

JWT Authentication in ASP.NET Core and Angular 8 – Part 2 Guide

Continue building secure apps with JWT in Angular 8 and ASP.NET Core. Learn about token refresh, role-based access, and protecting Angular routes in Part 2.

Oct 14, 2019
Secure JWT Authentication in .NET MAUI - Complete Guide
Web Development

Secure JWT Authentication in .NET MAUI – Complete Guide

Implement secure JWT authentication in .NET MAUI apps. Learn best practices, tips, and examples to protect your mobile & desktop applications.

Jun 13, 2025

Ready to Build Something Amazing?

Get in touch with Prishusoft – your trusted partner for custom software development. Whether you need a powerful web application or a sleek mobile app, our expert team is here to turn your ideas into reality.

image