标签: saaskit

在asp.net core 3.1中注册基于租户的认证方案

目前,我已经创建了一个 Identity server 4 Web 应用程序,其中包含具有默认客户端 ID 和机密的外部登录提供程序。但我的目标是基于租户注册 Azure、Google、Facebook 等身份验证提供程序。

我使用了SaasKit多租户程序集,在这里我尝试了app.usepertenant()中间件。但是UseGoogleAuthentication()方法已经过时了,所以我无法使用这个 usepertenant 中间件实现多租户身份验证。

当前代码,

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
   .AddMicrosoftAccount(option =>
     {
        option.ClientId = "clientid";
        option.ClientSecret = "clientsecret";
        option.SaveTokens = true;
     });
Run Code Online (Sandbox Code Playgroud)

预期的代码如下,

var authentication = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);

if (tenant.hasMicrosoft)
{
   authentication.AddMicrosoftAccount(option =>
   {
        option.ClientId = "clientid";
        option.ClientSecret = "clientsecret";
        option.SaveTokens = true;
   });
}

if (tenant.hasGoogle)
{
   authentication.AddGoogle(option =>
   {
        option.ClientId = "clientid";
        option.ClientSecret = "clientsecret";
        option.SaveTokens = true;
   });
}

authentication.AddCookie( options =>
 {
    options.SlidingExpiration = true; …
Run Code Online (Sandbox Code Playgroud)

authentication multi-tenant asp.net-core identityserver4 saaskit

13
推荐指数
1
解决办法
1657
查看次数