2017-05-14 71 views
0

我正在使用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'); 
     }); 
    }, 
); 

回答

0

根據錯誤信息,您需要將自己的Azure的Active Directory應用程序添加到貢獻者角色創建在Azure的通知中心的命名空間。

enter image description here


您可以按照下面也都記錄here的步驟。

  1. 轉到Azure portal並選擇訂閱

enter image description here

  • 選擇特定訂閱(資源組或資源)來分配應用程序。
  • enter image description here

  • 選擇訪問控制(IAM)
  • enter image description here

  • 選擇添加
  • enter image description here

  • 選擇貢獻者角色分配給您的AAD申請。
  • enter image description here

    +0

    我的用戶添加作爲貢獻者,訂閱和資源組的訂閱和資源組對通知樞紐全面進入,但我注意到,沒有分配給應用程序所有者當用戶我試圖添加我的用戶,即使它是擁有該帳戶的用戶,它也是無法點擊的。 – user3462064