端点属于不同的权限

Endpoint belongs to different authority

尝试将 Azure AD 用作带有 IdentityModel 包的 OpenID 提供程序

但是问题是它产生了错误的端点配置

var client = new HttpClient();

const string identityUrl = "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/v2.0";
const string restUrl = "https://localhost:44321";

var disco = await client.GetDiscoveryDocumentAsync(identityUrl);
if (disco.IsError)
{
    Console.WriteLine(disco.Error); 
    return;
}

returns 错误

Endpoint belongs to different authority: https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/authorize

openid-configuration 输出为

{"authorization_endpoint":"https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/authorize",
"token_endpoint":"https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/token" ... }

oauth2是在tenatID和version之间加的。我想这就是 openid 元数据验证失败的原因。

是否可以将 AzureAD 配置为 return openid 配置的正确元数据?

此致

你能找到解决办法吗?我能想出的唯一方法(远远不是最佳解决方案)是将端点添加到附加端点基地址列表中。否则,您必须将验证设置为 false,如上面的评论所述。

var client = httpClientFactory.CreateClient();
       var disco = await client.GetDiscoveryDocumentAsync(
            new DiscoveryDocumentRequest
            {
                Address = "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/v2.0",
                Policy =
                {
                    ValidateIssuerName = true,
                    ValidateEndpoints = true,
                    AdditionalEndpointBaseAddresses = { "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/token",
                                                        "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/authorize",
                                                        "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/discovery/v2.0/keys",
                                                        "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/devicecode",
                                                        "https://graph.microsoft.com/oidc/userinfo",
                                                        "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/logout"
                                                      }
                },
            }
        );

我也遇到了同样的问题,当我将 IdentityModel 升级到版本 2.16.1 时,问题就解决了

A​​zure AD 似乎需要按照 @flacid-snake 建议的其他终结点配置。将验证端点设置为 False 是一种安全威胁,应该避免。

最好的方法是使其可配置,最好在 UI 配置 SSO 服务器时使用。端点可以改变,而且应该很容易改变。如果您以后决定支持 Okta 或其他提供商并且他们需要额外的端点,这也会让事情变得更容易。

自 2021 年 6 月起,您还需要包含 Kerberos 端点,例如: https://login.microsoftonline.com/888861fc-dd99-4521-a00f-ad8888e9ecc8bfgh/kerberos(替换为您的目录租户 ID)。

如果您查看 IdentityModel 存储库中的代码,您会发现端点的默认验证通过执行“开始于”方法来验证它们。 https://github.com/IdentityModel/IdentityModel/blob/1db21e2677de6896bc11227c70b927c502e20898/src/Client/StringComparisonAuthorityValidationStrategy.cs#L46

那么您需要添加的 DiscoveryDocumentRequest Policy 字段中仅有的两个必需的 AdditionalEndpointBaseAddresses 是 "https://login.microsoftonline.com/<guid>""https://graph.microsoft.com/oidc/userinfo"