ASP.NET5 Sign in with Facebook

Source: Internet
Author: User

Original tutorial

To create a web app using VS2015:

This tutorial uses a Facebook account to sign in, and you need to add the relevant classes to open NuGet:

Search Microsoft.AspNet.Authentication.Facebook and install:

Right-click on the project properties to turn on SSL:

In the Configure method of Startup.cs, add:

1 Apps. Usefacebookauthentication (options =2            {3                 options. AppId = configuration["Authentication:Facebook:AppId"]; 4                 Options. Appsecret = configuration["Authentication:Facebook:AppSecret"]; 5             });

Open Appsettings.json Edit Facebook's AppID and Appsecret, where the database is directly used by the local library, which is VS2015 comes with and does not need to install SQL Server:

 authentication:facebook:appid, here is a authentication object that contains a Facebook object:

" Authentication " : {    "Facebook": {      "AppId" " xxxxxx " ,       " Appsecret " " xxxxxx "     }  }

Next sign up for Facebook apps:

Open https://developers.facebook.com/, login to your Facebook account, of course, there is a need for harmonious internet

Click Add New app:

Select website:

Select the Skip and Create App ID:

Fill in the name, email, select Category:

Click Settings:

To add an open platform:

Select website:

Here you need to fill in the callback address, this address is the HTTPS address above:

Copy the AppID and Appsecret into the Appsettings.json above:

Open the website, click Sign in, select Facebook login:

Will jump to the authorization page:

Then the error, because ASP.NET5 use EF to operate the database, at this time have not created a database, click Apply Migrations

Prompt Refresh page after success:

Jump to the registration page:

Sign in automatically after registration:

You can open SQL Server Object Explorer to view the database:

You will see that two records were inserted:

Similarly, you can sign in using Google Account:

Install Microsoft.AspNet.Authentication.Google:

Add the following code:

App. Usegoogleauthentication (options =                options. ClientId= configuration["Authentication:Google:ClientId"];                Options. Clientsecret= configuration["Authentication:Google:ClientSecret"];            });

Configuration, add:

ASP.NET5 Sign in with Facebook

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.