Fra*_*sky 7 c# multi-tenant asp.net-core identityserver4 asp.net-core-identity
我正在尝试实现为多租户应用程序处理SSO的IdentityServer。我们的系统将只有一个IdentityServer4实例来处理多租户客户端的身份验证。
在客户端,我正在使用acr_value传递租户ID。来自Startup.cs文件的一段代码如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthorization();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ClientId = "Client1";
options.ClientSecret = "secret";
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("offline_access");
options.Events.OnRedirectToIdentityProvider = n =>
{
if (n.ProtocolMessage.RequestType ==
OpenIdConnectRequestType.Authentication)
{
n.ProtocolMessage.AcrValues = "tenant:clientId1";
}
return Task.FromResult(0);
};
});
}
Run Code Online (Sandbox Code Playgroud)
对于身份服务器,使用具有ASP.NET Core身份的IdentityServer4。为了处理多租户客户端身份验证,我按照本文中Scott Brady针对ASP.NET Identity给出的说明进行操作:https : //www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy
我修改了UserStore来接收租户ID,但在为AccountController注入UserStore实例的那一刻,我无法检索通过的acr_value。
有人遇到过这个问题吗?
如果您还没有弄清楚,这里是解决方案
private readonly IIdentityServerInteractionService _interaction;
var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);
var tenant = context.Tenant;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2419 次 |
| 最近记录: |