Removing the user from Azure subscription programmatically (C#)

六月ゝ 毕业季﹏ 提交于 2019-12-13 08:25:09

问题


I want remove the users from Azure subscriptions programmatically.

We have lot of ways in the web to remove the AAD user but I could not find source to remove the users from Azure subscriptions.

Can we remove the user from Azure subscriptions programmatically?

How can we do this?


回答1:


Have you tried working with the Azure API Reference? Specifically authorization?

You may be interested in the Role Assignments API.

Here's a support article regarding those assignments and how to utilize the API: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-rest




回答2:


Finally i found the answer. We have to do multiple steps to remove the user from Subscription.

Before we start implementing the below steps you need to create Client Id and client secret and create auth token using those client id and secret.

First i am fetching all the users by below GET API. Here is URL for reference.

example get method URL for above reference is: https://management.azure.com/subscriptions/{your subscription id here}/providers/Microsoft.Authorization/roleAssignments?api-version=2015-07-01

Above URL will fetch all the Users principal Id(User GUID) and RoleAssigementID.

Then you can delete a specific user you want. Same above URL has reference to remove the User from Susbcription.

example delete method URL for above reference is: https://management.azure.com//subscriptions/{your subscription id here}/providers/Microsoft.Authorization/roleAssignments/{User role Assignment id}/providers/Microsoft.Authorization/roleAssignments/{User role Assignment id}?api-version=2015-07-01

You can find the role assignment id from the first step.

Extra information: First step will fetch principal id and role id but if you need other information of the user(ex: emailid, name, etc) you can use Graph API to fetch all information of the User. Here is the URL for reference.

Before calling this API, you need to create another auth token(which is different from above auth token) for this.

https://graph.windows.net/{your tenant id}/getObjectsByObjectIds?api-version=1.6



来源:https://stackoverflow.com/questions/51093012/removing-the-user-from-azure-subscription-programmatically-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!