【发布时间】:2017-10-13 12:20:35
【问题描述】:
我正在使用 node.js SDK 调用 Azure 通知中心 api,我使用 Azure Active Directory 注册了一个应用程序,还创建了一个资源组并将我的用户作为所有者添加到其中。但是调用 api 时出现此错误:
授权失败
具有对象 ID 的客户端“333848ca-f996-XXXXXXXXXXXX” '333848ca-f996-XXXXXXXXX' 无权执行 在范围内操作“Microsoft.NotificationHubs/namespaces/write” '/subscriptions/ef8e8e-XXXXXXXXXXXX/resourceGroups/notificationGroup/providers/Microsoft.NotificationHubs/namespaces/namespaceapp1
代码:
MsRest.loginWithServicePrincipalSecret(
My Subscription ID,
My Application Secret Key,
My Directory ID, // found under AD -> properties
(err, credentials) => {
if (err) throw err;
// eslint-disable-next-line
const client = new notificationHubsClient(credentials, AZURE_SUBSCRIPTION_ID);
const createNamespaceParameters = {
location: AZURE_LOCATION,
tags: {
tag1: 'value1',
tag2: 'value2',
},
};
client.namespaces.createOrUpdate(AZURE_RESOURCE_GROUP_NAME, req.body.name, createNamespaceParameters,
(error, result) => {
if (error) {
res.send(error);
}
console.info(`Namespace created${JSON.stringify(result, null, ' ')}`);
res.send('app created');
});
},
);
【问题讨论】: