(C# ASP.NET Core) Creating a Google OAuth App for Authentication

Social media based authentication requires us to create an oauth app on a social media platform such as google, facebook, twitter, github. This app provides us a client id and a client secret key for use in various classes that provide social media integration. In this tutorial we have a walkthrough for creating an oauth app on the google cloud console. Steps for other social media are similar - so you can take them as an exercise.
(Rev. 04-Jun-2024)

Categories | About |     |  


Getting Started

Login into your google console app and create or select a google console project. Some parts of the google console are billed so you must be careful on that.

On the menu on the left side locate OAuth consent screen and click it so that you see the OAuth consent screen as you are seeing here.

Select User Type as external. This option also allows us to add a few test users, which is convenient from a student's perspective. After that click Create, and allow the provisioning to take place.

Video Explanation (see it happen!)

Please watch the following youtube video:

OAuth Consent Screen

A form for app registration opens. It contains some fields that are mandatory, and some optional. The information you fill here is shown to the user when he begins his authentication process. Let's see these fields in detail.

See the linked video for a clearer explanation.

Give any readable name to your app. After that an email has to be provided. So enter an email that belongs to you. After that there is a section on App domain. Leave them empty for now because they are optional. And, towards the end there is another demand for email. Provide your email address here also.

Lastly, click the save button and allow the form to be saved.

Specifying the information to be collected

A page called Scopes opens next. This page will ask you to specifically declare the information that your app would be collecting from your end-users. Click on the Add or Remove Scopes button.

A sidebar opens that shows various options. We'll keep the things simple. So I have tickmarked email and profile.

See the linked video for a clearer explanation.

Scroll to the end of this list and locate a button called Update or it could be Save also. Click this button to save to the list of data that you would be collecting.

This is a full-screen view of the scopes page. We can scroll down to see other items on this page. The scopes we added are classified as non-sensitive scopes. Scrolling further down we can see a table for sensitive scopes.

Click the Save and Continue button now.

Add Test Users

After that a page for adding test users appears.

General public cannot authenticate through your app till the time it is published. Hence, we need to specify a few whitelist emails that will be able to authenticate during the testing phase.

See the linked video for a clearer explanation.

Add a test email that exists. After that save and continue.

With this your app registration should be complete. You can review the summary - but you can always come back to make changes whenever required.

Creating the Credentials

Next click on the Credentials tab on the left hand side menu to open the Credentials page.

See the linked video for a clearer explanation.

Click on the Create Credentials button. A drop down appears. Select the OAuth Client ID option and click it to open a form called Create OAuth Client ID. Let's see it in full screen!

Select Application Type as Web Application.

After that give any readable name, and scroll further down this page.

Authorized javascript origins can be kept empty for now. Scroll down to the redirect URIs. This is the most important field for our ASPNET Core projects.

Type your localhost address with the same port as of your application.

The path must end in signin-google exactly as you are seeing here. This is hard-coded in the nuget implementations of ASPNET Core libraries that will connect to this OAuth app.

Finally, click Create and within a few seconds you should see a messagebox containing your client id and client secret. Take note of them for use in the next tutorials. Thanks!

This Blog Post/Article "(C# ASP.NET Core) Creating a Google OAuth App for Authentication" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.