.net核心:LinkedIn身份验证

时间:2019-06-20 15:24:08

标签: c# asp.net-core

我正在为.Net核心应用程序使用LinkedIn身份验证。

我已经配置了linkedIn选项,但是maybe_array&.-(odds)&.average 返回null?

await _signInManager.GetExternalLoginInfoAsync()

1 个答案:

答案 0 :(得分:0)

似乎您正在使用具有LinkedIn身份验证的ASP.NET Identity。我建议您可以按照以下步骤实现该目标:

  1. 创建Individual User Account身份验证模板Asp.net Core应用程序。

  2. 安装Nuget软件包AspNet.Security.OAuth.LinkedIn以在Web应用程序中实现LinkedIn身份验证。

  3. 在解决方案资源管理器中右键单击该项目,然后从上下文菜单中选择Manage User Secrets,将打开一个secrets.json文件,并将您的凭据放入其中:

    {
        "Authentication:LinkedIn:ClientId": "YourClientID",
        "Authentication:LinkedIn:ClientSecret": "YourSecret"
    }
    
  4. Startup.cs文件中并修改ConfigureServices方法:

    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(
            Configuration.GetConnectionString("DefaultConnection")));
    services.AddDefaultIdentity<IdentityUser>()
        .AddDefaultUI(UIFramework.Bootstrap4)
        .AddEntityFrameworkStores<ApplicationDbContext>();
    
    services.AddAuthentication().AddLinkedIn(options =>
    {
        options.ClientId = Configuration["Authentication:LinkedIn:ClientId"];
        options.ClientSecret = Configuration["Authentication:LinkedIn:ClientSecret"];
    });
    
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);