【问题标题】:authority_not_in_valid_list: 'authority' is not in the list of valid addressesauthority_not_in_valid_list:“权限”不在有效地址列表中
【发布时间】:2024-01-16 23:22:01
【问题描述】:

我正在尝试从我的客户端应用程序调用经过身份验证的 API。但是,在制作 AcquireTokenAsync 时,我收到以下错误“authority_not_in_valid_list: 'authority' is not in the list of valid address

这是我的代码 sn-p:

resourceUrl = "https://myApiEndPoint.com";

var clientCredential =
     new ClientCredential( myClientAppId, myClientSecretKey );

// myClientAppId 和 myClientSecretKey 是来自 Azure 门户的值

var authContext = 
    new AuthenticationContext( "https://my_authority/myApiEndPoint");

return await authContext.AcquireTokenAsync( resourceUrl, clientCredential );

在我的应用程序客户端 ID 的 Azure 门户中,我已授予访问 https://myApiEndPOint.com api 的委派权限。

对可能导致此问题的原因以及不在有效列表中的含义有何想法?

【问题讨论】:

    标签: azure authentication oauth active-directory access-token


    【解决方案1】:

    我明白:

    • 您在 Azure 门户中创建了应用程序,因此授权是 Azure AD 终结点。所以权限大概是https://login.microsoftonline.com/common?还是您有充分的理由使用“https://my_authority”?

    • 您已授予委派权限以访问 API。这意味着您的应用程序将以用户的名义访问 API。但是,您使用的 AcquireTokenAsync 方法正在使用“ClientCredential”流(意味着使用应用程序机密) 您可能更愿意使用另一个覆盖传递 resourceUri、clientId、...

    如果这是您的用例,我建议您查看active-directory-dotnet-webapi-onbehalfof 示例(请参阅here

    【讨论】: