0
votes

Am using the node.js SDK to call the Azure notification hub api, I registered an application using Azure Active directory also i created a resource group and added my user to it as owner. But am getting this error when calling the api:

AuthorizationFailed

The client '333848ca-f996-XXXXXXXXXXXX' with object id '333848ca-f996-XXXXXXXXX' does not have authorization to perform action 'Microsoft.NotificationHubs/namespaces/write' over scope '/subscriptions/ef8e8e-XXXXXXXXXXXX/resourceGroups/notificationGroup/providers/Microsoft.NotificationHubs/namespaces/namespaceapp1

The code:

  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');
        });
    },
  );
1

1 Answers

0
votes

According to the error message, you'll need to add your Azure Active directory application to the Contributor role for creating the namespace in Azure Notification Hub.

enter image description here


You can follow the steps below which are also documented here.

  1. Go to Azure portal and select Subscriptions.

enter image description here

  1. Select the particular subscription (resource group or resource) to assign the application to.

enter image description here

  1. Select Access Control (IAM).

enter image description here

  1. Select Add.

enter image description here

  1. Select the Contributor role to assign to your AAD application.

enter image description here