External Login (Facebook and Google) with database in ASP .Net Core Web Application (.Net 5)

KANHAIYA TYAGI
3 min readJun 24, 2021

--

This tutorial with code examples shows how to enable your users to sign in with their Facebook account or Google Account using a sample ASP.NET Core 5.0.

Prerequisites

  1. Visual Studio 2019 any edition.
  2. MSSQL Server 2017 or higher.
  3. Google and Facebook Account.
  4. .Net 5 SDK.

Steps For facebook

  1. Open facebook for developers page and logged In

2. Click on Create App and Select app type “None” and click on continue

3. Click on my apps and select “Testing”

4. Click on add project, Select the “Facebook Login” and click on “setup”

5. Click on setting under product/Facebook Login and put “http://localhost:5000/signin-facebook” into “Valid OAuth Redirect URIs” and Finally save changes.

6. Go to Setting, Click on base and copy both App ID (Client Id)and App Secret (Client Secret)

and paste into the notepad

Steps For Google

1.Follow the guidance in Integrating Google Sign-In into your web app (Google documentation).

  • In the Credentials page of the Google console, select CREATE CREDENTIALS > OAuth client ID.
  • In the Application type dialog, select Web application. Provide a Name for the app.
  • In the Authorized redirect URIs section, select ADD URI to set the redirect URI. Put redirect URI: https://localhost:5000/signin-google
  • Select the CREATE button.
  • Copy Client Id and Client Secret in notepad

Integration into the Project

  1. Download ExternalAuth project from GitHub.
  2. Change connection string from appsetting.json file i.e replace server name, user id and password
  3. Open package manager console(Tools/Nuget Package Manager/Package Manager Console)
  4. Run “update-database” command for migration
  5. Replace client id and client secret in appsetting.json

6. Run application click on signin on top

7. You will see interface like below

8. Choose any method, After login you will see user logged In and user created into the database.

Thank you for reading this article

--

--

KANHAIYA TYAGI

Engineer, GIS, .NET, JavaScript, jQuery, Azure, Angular