DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • GDPR Compliance With .NET: Securing Data the Right Way
  • How to Enhance the Performance of .NET Core Applications for Large Responses
  • Developing Minimal APIs Quickly With Open Source ASP.NET Core
  • Revolutionizing Content Management

Trending

  • Building a Real Pipeline With senro: Monorepos, Caching, and Triggers
  • Kill the Worker, Keep the Research: Build a Recoverable LangGraph Agent on Temporal
  • Why Your AI Agent Works in the Demo and Fails in Production
  • Vision-Language Models in 2026: From Research Breakthroughs to Cloud-Native Production Systems

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. How to Add Social Media Authentication to ASP.NET Core

How to Add Social Media Authentication to ASP.NET Core

Today, I'd like to share how you can go about enabling social media authorization for an ASP.NET Core application very easily.

By 
Simone Chiaretta
·
Dec. 27, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

adding social media authentication is easy with asp.net core. you start by creating another project, like you would with an asp.net core mvc project, and selecting individual user accounts as the authentication mode. this way the project template will add the database entities, controllers, and views to collect and store all the information needed to create a private site where users can register either directly (providing a username and password) or via oauth providers like facebook, twitter, google, microsoft, github, and others.

adding a social login is just a matter of adding the right nuget package and configuring the authentication provider in the configureservice method in the startup class. for example, to add a facebook login, add the nuget package, we'd use the following: microsoft.aspnetcore.authentication.facebook . then add the following lines of code in the configureservice method:

services.addauthentication().addfacebook(facebookoptions =>
{
    facebookoptions.appid = configuration["authentication:facebook:appid"];
    facebookoptions.appsecret = configuration["authentication:facebook:appsecret"];
});

now you have to register a new application on the facebook developer portal in order to get the appid and appsecret needed to authenticate your application with facebook. go to the url https://developers.facebook.com/apps/ and click on the add a new app button and add the basic information for your app. once that's done, go to the settings and enter the url for the oauth redirect page, which is /signin-facebook (but you need to specify the absolute url, http://localhost:nnn ). this route is added by the nuget package for the facebook authentication.

the last thing is to retrieve the appid and appsecrets needed for the application to work. for this, go to the dashboard inside the developer portal:

now that you have these values, you have to store them in the settings of your application. since this is sensitive data, you don't want to accidentally commit them to a public source repository, so it's better to store them in the user secrets.

the file is stored in the user profile, which is still easily readable, but, in theory, only by its owner. the, in production, this information can be passed to the app in different ways, like shown when explaining the configuration of app settings inside the webhost .

{
  "authentication": {
    "facebook": {
      "appid": "myappid",
      "appsecret": "myappsecret"
    }
  }
}

now just launch the site and you'll see a new button to sign-in and log-in via facebook

authentication ASP.NET Core ASP.NET Media (communication)

Published at DZone with permission of Simone Chiaretta. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • GDPR Compliance With .NET: Securing Data the Right Way
  • How to Enhance the Performance of .NET Core Applications for Large Responses
  • Developing Minimal APIs Quickly With Open Source ASP.NET Core
  • Revolutionizing Content Management

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook