【发布时间】:2021-04-23 02:23:21
【问题描述】:
我正在努力通过后请求通过 Azure 功能从“https://login.microsoftonline.com/common/oauth2/token”获取令牌。该令牌将授予通过 CSOM 访问 SharePoint 的权限。这是我的代码 sn-p 与发布请求:
var clientId = defaultAADAppId;
var body = $"resource={resource}&client_id={clientId}&grant_type=password&username={HttpUtility.UrlEncode(username)}&password={HttpUtility.UrlEncode(password)}";
using (var stringContent = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded"))
{
var result = await httpClient.PostAsync(tokenEndpoint, stringContent);
var tokenResult = JsonSerializer.Deserialize<JsonElement>(result);
var token = tokenResult.GetProperty("access_token").GetString();
}
在本地测试时,无论是在 Visual Studio 中运行该功能还是尝试使用 Postman 时,我都能获得访问令牌。但是,一旦我将函数发布到 Azure 中的函数应用程序,我就会收到以下错误消息:
“AADSTS53003:访问已被条件访问策略阻止。访问策略不允许颁发令牌”
我已在门户中启用应用注册,如前所述,在我将所有内容发布到 Azure 之前一切正常。
关于如何解决这个问题的任何想法?
【问题讨论】:
-
查看这里:docs.microsoft.com/en-us/azure/active-directory/develop/…。建议分辨率:
Check the security policies that are defined on the tenant level to determine if your request meets the policy requirements. -
也可以在这里查看:login.microsoftonline.com/error。粘贴错误号
AADSTS53003。结果:If this is unexpected, see the conditional access policy that applied to this request in the Azure Portal.
标签: c# azure-functions access-token csom azure-function-app