【问题标题】:Not allowed users are authentication in my Azure AD Application Multi Tenant不允许用户在我的 Azure AD 应用程序多租户中进行身份验证
【发布时间】:2017-04-23 22:05:31
【问题描述】:

我在 Azure AD 中配置了两个租户。我的用户在我的租户中验证成功,但其他租户的其他用户可以访问我的应用程序。

我的申请有什么问题?我在我的代码中使用 OpenId Connect 协议,例如:

app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuer = false,
                },
                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    SecurityTokenValidated = (context) =>
                    {
                        return Task.FromResult(0);
                    },
                    AuthenticationFailed = (context) =>
                    {
                        context.HandleResponse();
                        return Task.FromResult(0);
                    }
                }
            });

我是否在 Azure 上设置了错误?

有人帮帮我吗?

谢谢,

维莱拉

【问题讨论】:

  • 我不清楚您在这里遇到了什么问题。能否请您复制并粘贴您收到的错误消息?

标签: azure authentication c#-4.0 azure-active-directory openid-connect


【解决方案1】:

我在 Azure AD 中配置了两个租户。

租户对应于 Azure Active Directory。因此,当有两个租户时,这意味着您有两个不同的 Azure Active Directory。(有关详细概念,请参阅 here

要启用多租户应用程序,我们需要从old Azure portal 启用它并找到您的应用程序。然后您可以参考下图进行设置:

更新(限制 sepcifc 租户访问多租户应用)

 app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = ClientId,
                    Authority = Authority,
                    TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                    {
                        // instead of using the default validation (validating against a single issuer value, as we do in line of business apps), 
                        // we inject our own multitenant validation logic
                        ValidateIssuer = false,
                    },
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {                    
                        // we use this notification for injecting our custom logic
                        SecurityTokenValidated = (context) =>
                        {
                            // retriever caller data from the incoming principal
                            string issuer = context.AuthenticationTicket.Identity.FindFirst("iss").Value;    
                            var issuer1 = "";
                            var issuer2 = "";
                            if ((issuer!=issuer1)&& (issuer != issuer2))
                            // the caller was neither from a trusted issuer - throw to block the authentication flow
                            throw new SecurityTokenValidationException();                            
                        return Task.FromResult(0);
                       }
                   }
              });

【讨论】:

  • 谢谢飞雪,但是当我的应用程序配置了多租户时,所有其他拥有 Azure 帐户的用户都可以进入我的应用程序。我只需要允许我的租户(如果有两个租户)。谢了。
  • 多租户应用程序默认启用 Azure AD 上的所有租户,如果要限制租户,则需要自定义令牌验证。我修改了原始帖子以附加代码示例。
  • 没关系的飞雪。在我看来,在我的场景中,多租户选项并不安全,但是当我获得租户并与我的租户进行比较时,它的效果很好。我认为最好将我的租户和 clientId 代码放在我的 web.config 中,并在我获得 IIS 中的 app.Properties["host.AppName"] 时在 app.UseOpenIdConnectAuthentication 代码之后切换它。我对你所做的一切表示感谢!这是一种乐趣。 Tks
  • @Vilela 欢迎您。如果回复有助于解决问题,请考虑接受它作为答案,以便有相同问题的其他社区可以轻松识别答案。
  • 你知道如何使用与 Win.Forms 相同的身份验证 Azure AD 吗?我可以使用相同的协议 UseOpenIdConnectAuthentication 吗?
猜你喜欢
  • 2023-02-09
  • 2020-08-26
  • 2015-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-13
相关资源
最近更新 更多