多个Facebook客户端aspnet核心2

时间:2018-04-10 14:47:35

标签: asp.net-core asp.net-core-2.0 facebook-authentication asp.net-authentication

我有两个不同的应用程序在Aspnet Core 2.0中调用相同的api。在简单的启动代码中,我有

IList<IFormFile> files

没有警告但是当我尝试运行迁移时,错误显示

...
  services.AddAuthentication()
           .AddGoogle(options =>
           {
               options.ClientId = WebConfig.GoogleClientId;
               options.ClientSecret = WebConfig.GoogleClientSecret;
           })
           .AddFacebook(options =>
           {
               options.ClientId = WebConfig.FacebookConsumerClientId;
               options.ClientSecret = WebConfig.FacebookConsumerClientSecret;
               options.SaveTokens = true;
           })
           .AddFacebook(options =>
           {
               options.ClientId = WebConfig.FacebookProviderClientId;
               options.ClientSecret = WebConfig.FacebookProviderClientSecret;
               options.SaveTokens = true;
           })
           .AddOAuthValidation();

如何在Aspnet Core 2.0中注册多个Facebook客户端?我在另一篇文章中读到,在aspnet core 1.x中你可以设置不同的方案。我也可以通过添加

来做到这一点
 "scheme already exists:facebook"

和其他

options.SignInScheme = "facebook1";

但我不确定我还有什么需要做的吗?

1 个答案:

答案 0 :(得分:0)

正如您所说,您应为每个身份验证设置不同的架构名称。你可以这样做:

services.AddAuthentication()
       .AddGoogle(options =>
       {
           options.ClientId = WebConfig.GoogleClientId;
           options.ClientSecret = WebConfig.GoogleClientSecret;
       })
       .AddFacebook("facebook1", options =>
       {
           options.ClientId = WebConfig.FacebookConsumerClientId;
           options.ClientSecret = WebConfig.FacebookConsumerClientSecret;
           options.SaveTokens = true;
       })
       .AddFacebook("facebook2", options =>
       {
           options.ClientId = WebConfig.FacebookProviderClientId;
           options.ClientSecret = WebConfig.FacebookProviderClientSecret;
           options.SaveTokens = true;
       })
       .AddOAuthValidation();