【问题标题】:Multiple Azure AD Authentication Identity Server 4多个 Azure AD 身份验证身份服务器 4
【发布时间】:2020-03-27 14:16:26
【问题描述】:

我想知道是否可以使用 IdentityServer 4 设置一个 .NET Core 应用程序,该应用程序可以对多个 AzureAd 配置进行身份验证。

目前您可以像这样添加 1 个 AzureAD 配置:

services.AddAuthentication()
            .AddAzureAD(options => Configuration.Bind("AzureAd", options));

但我希望能够使用 AzureAd 对来自多个组织的用户进行身份验证。如此不同的 TenantId...等

这必须根据在 UI 中选择的组织即时完成。

我怎样才能做到这一点?

【问题讨论】:

    标签: asp.net-core azure-active-directory identityserver4


    【解决方案1】:

    你可以使用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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      相关资源
      最近更新 更多