问题描述
var authorityUri = $"https://login.microsoftonline.com/{tenantId}";
var scopes = new System.Collections.Generic.List<string> { "https://graph.microsoft.com/.default" };
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(appId,clientSecret,tenantId,AzureEnvironment.AzureGlobalCloud);
var authenticated1 = Microsoft.Azure.Management.Fluent.Azure.Configure().Authenticate(credentials);
IRoleDeFinition Rdef = authenticated1.RoleDeFinitions.GetByScopeAndRoleName("/","Owner");
到目前为止还好。内部 Rdef 为我提供角色名称、ID 和名称,现在我正在尝试列出该角色的订阅范围内的所有用户。
var roleassignement1 = authenticated1.RoleAssignments.ListByScopeAsync("/");// GetById("*****")// .GetByScopeAsync("subscriptions/322dac8a-416c-4de6-977c-e6b21344651c","Owner");
这里的作用域是什么,我添加了订阅/子ID作为作用域。我想要做的是列出订阅中的所有 RBAC。 我究竟做错了什么?任何指针表示赞赏。
问候。
解决方法
只需更改以下代码:
var roleassignement1 = authenticated1.RoleAssignments.ListByScopeAsync("/");
到
var roleassignement1 = await authenticated1.RoleAssignments.ListByScopeAsync("subscriptions/322dac8a-416c-4de6-977c-e6b21344651c");
,然后它就可以工作了。