Advanced features of Microsoft/Facebook authentifcation not available on Asp .Net Core RC1

一笑奈何 提交于 2020-01-02 07:34:26

问题


I'm working on a small ASP .NET Core RC1 application and I'm trying to implement the Microsoft/Facebook authentification.

The following tutorial is really great and explain all the steps needed: http://www.oauthforaspnet.com/providers/microsoft/

But if I try to use the "advanced" features (like using the Provider property), this one is not available. I've added the following Nuget references in project.json:

"Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final", "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-rc1-final",

But I'm not able to use the FacebookAuthenticationProvider / FacebookProvider.

According to my research over the Net, it looks like that was possible using Beta 7 / Beta 8 but does anyone have successfully implemented the feature in RC 1?

Thanks!


回答1:


In ASP.NET Core 1.x, all the OAuth2 social providers (even the ones developed by the community) have been updated to use the new OAuth2 generic middleware.

As part of this change, we've removed the provider-specific classes to use a single events hook named OAuthEvents, which replaces Katana's FacebookAuthenticationProvider and co.

Here's an example using the Google provider:

app.UseGoogleAuthentication(new GoogleOptions
{
    ClientId = "client_id",
    ClientSecret = "client_secret",

    Events = new OAuthEvents
    {
        OnCreatingTicket = context =>
        {
            // Extract the "language" property from the JSON payload returned by
            // the user profile endpoint and add a new "urn:language" claim.
            var language = context.User.Value<string>("language");
            context.Identity.AddClaim(new Claim("urn:language", language));

            return Task.FromResult(0);
        }
    }
});


来源:https://stackoverflow.com/questions/35623873/advanced-features-of-microsoft-facebook-authentifcation-not-available-on-asp-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!