asp.net-core - 多个 Azure AD 身份验证身份服务器 4
问题描述
我想知道是否可以使用 IdentityServer 4 设置一个 .NET Core 应用程序,该应用程序可以对多个 AzureAd 配置进行身份验证。
目前,您可以像这样添加 1 个 AzureAD 配置:
services.AddAuthentication()
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
但我希望能够使用 AzureAd 对来自多个组织的用户进行身份验证。如此不同的 TenantId ...等
这必须根据 UI 中选择的组织即时完成。
我怎样才能做到这一点?
解决方案
您可以使用AddOpenIdConnect
中间件:
services.AddAuthentication()
.AddOpenIdConnect("AADTenant1", "AADTenant1", options =>
{
options.ClientId = "<app1>";
options.Authority = "https://login.microsoftonline.com/<tenant1>/";
options.CallbackPath = "/signin-oidc-aadtenant1";
options.SaveTokens = true;
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
})
.AddOpenIdConnect("AADTenant2", "AADTenant2", options =>
{
options.ClientId = "<app2>";
options.Authority = "https://login.microsoftonline.com/<tenant2>/";
options.CallbackPath = "/signin-oidc-aadtenant2";
options.SaveTokens = true;
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
})
并触发您想要挑战的计划:
var callbackUrl = Url.Action("ExternalLoginCallback");
var props = new AuthenticationProperties
{
RedirectUri = callbackUrl,
Items =
{
{ "scheme", provider },
{ "returnUrl", returnUrl }
}
};
return Challenge(provider, props);
推荐阅读
- liferay-6 - 在 Java/JEE 中调试多个 Web 项目
- javascript - Node.js 根据其值返回对象键
- ios - 我们可以避免显示推送通知吗
- powershell - 数组中的PowerShell字符串变量到数组变量
- r - R:绘制具有 NA 值的图
- swift - AudioKit AKMusicTrack 不播放 MIDI
- angular - 我的 ionic3 代码在发出 http 请求时提示这些错误
- ios - 通过代码添加 UIView 时出现重叠问题
- linux - Linux内核模块:BUG:无法在0000000080cb7fb8处处理内核分页请求
- docker - 自托管注册表和 docker 中的自己的证书有什么风险?