Search code examples
azureazure-active-directoryazure-sdk

Add Azure user to resource group with nodejs


Using the Node.js SDK, I've created a user and a resource group. How can I now assign the user to the resource group as an owner?


Solution

  • You could refer to this example.

    authzClient.roleAssignments.create(scope, assignmentGuid, roleCreateParams, function (err, roleAssignment, req, res) {
      if (err) {
        console.log('\nError occured while creating the roleAssignment: \n' + util.inspect(err, { depth: null }));
        return;
      }
    

    According to your need, you need the example.

    Owner role id is 8e3af657-a8ff-443c-a75c-2fe8c4bcb635.

    scope should be like this /subscriptions/{subscription-id}/resourceGroups/myresourcegroup1.

    Replace application id to your user object id.

    Also, you could use Azure rest API to do this, please refer to this link.