Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.3 KiB

社交/外部登录

ASP.NET Core MVC / Razor Pages UI

帐户模块已配置为开箱即用的处理社交或外部登录. 你可以按照ASP.NET Core文档向你的应用程序添加社交/外部登录提供程序.

示例: Facebook 认证

按照ASP.NET Core Facebook集成文档向你应用程序添加Facebook登录.

添加NuGet包

添加[Microsoft.AspNetCore.Authentication.Facebook]包到你的项目. 基于你的架构,可能是 .Web,.IdentityServer(对于分层启动)或 .Host 项目.

配置提供程序

在你模块的 ConfigureServices 方法中使用 .AddFacebook(...) 扩展方法来配置客户端:

context.Services.AddAuthentication()
    .AddFacebook(facebook =>
    {
        facebook.AppId = "...";
        facebook.AppSecret = "...";
        facebook.Scope.Add("email");
        facebook.Scope.Add("public_profile");
    });

最佳实践是使用 appsettings.json 或ASP.NET Core用户机密系统来存储你的凭据,而不是像这样硬编码值. 请参阅微软文档了解如何使用用户机密.