注册和租户入职-如何仅在被邀请加入应用程序时才允许

问题描述

Microsoft在多租户应用程序和身份管理方面拥有guide。他们解释了租户管理员(或租户用户)如何在使用用户配置文件的应用程序中提供同意。但是,我也有相反的兴趣:作为应用程序所有者,同意特定租户使用该应用程序。我们只希望允许已签署SLA的应用程序上的租户。

我们如何才能将租户“白名单”,以便只有已知的租户才能在我们的应用程序中注册

解决方法

Azure AD不会限制租户的用户可以登录到该应用程序,最好的方法是将有效的令牌发行者指定给应用程序一侧的令牌验证器。

ASP.NET Core示例:

// Inside .AddOpenIdConnect()
o.TokenValidationParameters = new TokenValidationParameters
{
    // NOTE: We should not turn issuer validation off
    // We should instead list the valid issuers
    // You can find your issuer URI at: https://login.microsoftonline.com/tenant-id-here/v2.0/.well-known/openid-configuration
    // It's in the "issuer" property
    NameClaimType = "name",ValidIssuers = new[] // THIS IS IMPORTANT Only accept tokens from these tenants
    {
        $"https://login.microsoftonline.com/{authSettings.EmployeeTenantId}/v2.0",$"https://login.microsoftonline.com/{authSettings.PartnerTenantId}/v2.0"
    }
};

有关更多详细信息,请参阅博客-Best practices for N-tenant Azure AD applications