Azure:尝试创建通知中心namesapce时授权失败

问题描述:

我正在使用node.js SDK来调用Azure通知中心api,我使用Azure Active目录注册了一个应用程序,同时我创建了一个资源组并添加了我的用户作为它所有者。但我调用API时收到此错误:Azure:尝试创建通知中心namesapce时授权失败

AuthorizationFailed

客户 '333848ca-F996-XXXXXXXXXXXX' 与对象ID '333848ca-F996-XXXXXXXXX' 没有授权执行 行动“ Microsoft.NotificationHubs /命名空间/写 '过度范围 ' /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'); 
     }); 
    }, 
); 

根据错误信息,您需要将自己的Azure的Active Directory应用程序添加到贡献者角色创建在Azure的通知中心的命名空间。

enter image description here


您可以按照下面也都记录here的步骤。

  1. 转到Azure portal并选择订阅

enter image description here

  1. 选择特定订阅(资源组或资源)来分配应用程序。
  2. enter image description here

    1. 选择访问控制(IAM)
    2. enter image description here

      1. 选择添加
      2. enter image description here

        1. 选择贡献者角色分配给您的AAD申请。
        2. enter image description here

        开始=>
      开始=>
    开始=>
开始=>
+0

我的用户添加作为贡献者,订阅和资源组的订阅和资源组对通知枢纽全面进入,但我注意到,没有分配给应用程序所有者当用户我试图添加我的用户,即使它是拥有该帐户的用户,它也是无法点击的。 – user3462064