【发布时间】:2016-10-06 10:59:11
【问题描述】:
我正在尝试使用 NodeJs 访问 Azure AD 的一些详细信息。我可以获得访问令牌 OK,但是每当我尝试使用 Graph API 调用任何东西(在这种情况下只是所有组的列表)时,它都会说我有 “权限不足,无法完成操作。”
我已经进入 AD 中的应用程序并添加了所有权限(只是为了确保),但我仍然收到此错误 - 我错过了什么吗?这是我的代码:
var msRestAzure = require('ms-rest-azure');
var graphRbacManagementClient = require('azure-graph');
var tenantId='';
// Enter your tenant ID here which can be found from your Azure AD URL
// Eg. https://manage.windowsazure.com/example.com#Workspaces/ActiveDirectoryExtension/Directory/<TenantId>/users
var clientId = ''
var clientSecret = ''
console.log('Starting');
msRestAzure.loginWithServicePrincipalSecret(clientId, clientSecret, tenantId, { tokenAudience: 'graph' }, function (err, credentials, subscriptions) {
if(err){
console.log('Could not get token', err)
}
console.log('Logged In');
var client = new graphRbacManagementClient(credentials, tenantId);
console.log("Client created");
client.groups.list({}, function(err, result){
if(err){
console.log('Could not list groups', err)
}
})
});
返回的错误是:
{
"statusCode": 403,
"request": {
"rawResponse": false,
"queryString": {
},
"method": "GET",
"headers": {
"x-ms-client-request-id": "2b0e7464-bf4f-41d3-8440-38797bf0d72b",
"accept-language": "en-US",
"Content-Type": "application/json; charset=utf-8"
},
"url": "https://graph.windows.net/5a677fc4-23da-4e7a-a0fa-75f2c53e9c90/groups?api-version=1.6",
"body": null
},
"response": {
"body": "{\"odata.error\":{\"code\":\"Authorization_RequestDenied\",\"message\":{\"lang\":\"en\",\"value\":\"Insufficient privileges to complete the operation.\"}}}",
"headers": {
"cache-control": "no-cache",
"pragma": "no-cache",
"content-type": "application/json;odata=minimalmetadata;streaming=true;charset=utf-8",
"expires": "-1",
"server": "Microsoft-IIS/8.5",
"ocp-aad-diagnostics-server-name": "F3xU7bkLCvTOf62bCyNdsiLFnuyfFODP68vB9RmoAS0=",
"request-id": "f8404560-e300-4cd1-8a4b-a6487b06f7a2",
"client-request-id": "97cd97fa-448f-44bb-87dc-7d48505e80db",
"x-ms-dirapi-data-contract-version": "1.6",
"ocp-aad-session-key": "REMOVED",
"x-content-type-options": "nosniff",
"dataserviceversion": "3.0;",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"access-control-allow-origin": "*",
"x-aspnet-version": "4.0.30319",
"x-powered-by": "ASP.NET, ASP.NET",
"duration": "1097838",
"date": "Wed, 05 Oct 2016 14:10:41 GMT",
"connection": "close",
"content-length": "139"
},
"statusCode": 403
},
"body": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation."
}
}
为了测试,我已向此客户端添加了图形和 azure AD 的所有权限:
【问题讨论】:
-
您能否发布完整的错误消息(包括相关 ID 和时间戳)?您还可以发布您配置应用程序拥有的权限的屏幕截图吗?
-
在完整的错误消息中添加 - 无法在任何地方找到相关 ID,我该如何找到?
-
您是否检查过在 Azure Functions 之外运行完全相同的东西是否有效?如果没有,那么您可以通过删除对 Azure Functions 的所有引用来简化您的问题。
-
抱歉,我忘记了 Azure AD Graph API 响应不包含在错误消息正文中。我正在寻找
request-id标头。 -
您能否附上您为应用程序配置了哪些权限的屏幕截图?
标签: azure azure-active-directory azure-ad-graph-api