我正在尝试从我的客户端应用程序调用经过身份验证的 API。但是,在进行 AcquireTokenAsync 时,我收到以下错误“authority_not_in_valid_list: 'authority' 不在有效地址列表中”
这是我的代码片段:
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 门户中创建了应用程序,因此权限是 Azure AD 终结点。因此权限大概是https://login.microsoftonline.com/common ?或者您有充分的理由使用“https://my_authority”吗?
您已授予访问 API 的委托(delegate)权限。这意味着您的应用程序将以用户的名义访问 API。但是,您使用的 AcquireTokenAsync 方法正在使用“ClientCredential”流程(意味着使用应用程序 secret ) 您可能更想使用另一个覆盖来传递resourceUri、clientId...
如果这是您的用例,我建议您查看active-directory-dotnet-webapi-onbehalfof示例(参见here)
关于azure - 权限不在有效列表中 : 'authority' is not in the list of valid addresses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46085415/