External Login (Facebook and Google) with database in ASP .Net Core Web Application (.Net 5)
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
- Visual Studio 2019 any edition.
- MSSQL Server 2017 or higher.
- Google and Facebook Account.
- .Net 5 SDK.
Steps For facebook
- 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
- Download ExternalAuth project from GitHub.
- Change connection string from appsetting.json file i.e replace server name, user id and password
- Open package manager console(Tools/Nuget Package Manager/Package Manager Console)
- Run “update-database” command for migration
- 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