简体   繁体   中英

IServiceCollection.AddFacebookAuthentication - no definition and no method found trying to add facebook authentication in asp.net core

I'm on a asp.net core 1.1 project, adding Facebook authentication. For reference, I didn't start the project as a "use identity", and instead started an empty project and moved over those items until I had a clean build (views, models, startup.cs changes, etc).

I added the Nuget package:

Microsoft.AspNetCore.Authentication.Facebook

I followed the MSDN instructions here: https://learn.microsoft.com/en-us/as.net/core/security/authentication/social/facebook-logins

I got down to adding this, adding it to my Startup.cs in my ConfigureServices method, I get an error on.AddFacebookAuthentication :

using Microsoft.AspNetCore.Authentication.Facebook;
using Microsoft.AspNetCore.Authentication;

//other code and sutff

services.AddFacebookAuthentication(facebookOptions =>
{
    facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
    facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});

The error I'm seeing:

Severity Code Description Project File Line Suppression State Error CS1061 'IServiceCollection' does not contain a definition for 'AddFacebookAuthentication' and no extension method 'AddFacebookAuthentication' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

I believe in 1.x you don't add that with services but instead in configure method like this:

app.UseFacebookAuthentication(facebookOptions =>
{
    facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
    facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];

});

but in 2.0 it will be done with services and not like this

Facebook external login setup in ASP.NET Core

  • Install Nuget Package

Microsoft.AspNetCore.Authentication.Facebook

  • Startup.cs

services.AddAuthentication().AddFacebook(option => { option.AppId = "xxx-xxx-xxx"; option.AppSecret = "xxx-xxx-xxx"; });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM