目前,我已经创建了一个使用外部登录提供程序和默认客户端 id 和密钥的 Identity Server 4 Web 应用程序。但我的目标是基于租户注册 Azure、Google 和 Facebook 等身份验证提供程序。
我使用了 SaasKit 多租户程序集,这里我尝试使用 app.usepertenant() 中间件。但 UseGoogleAuthentication() 方法已过时,因此我无法使用这个 usepertenant 中间件实现多租户身份验证。
当前代码:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddMicrosoftAccount(option =>
{
option.ClientId = "clientid";
option.ClientSecret = "clientsecret";
option.SaveTokens = true;
});
预期的代码如下所示:
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;
options.ExpireTimeSpan = new TimeSpan(7, 0, 0, 0);
});