加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Azure AD Graph API – 使用C#将用户分配给应用程序

发布时间:2020-12-15 21:01:22 所属栏目:百科 来源:网络整理
导读:我发现应用程序可以在这个答案中分配给用户,但似乎无法弄清楚如何使用C#来做到这一点.下面是我正在尝试的 JSON和C#. Azure Active Directory: assign user to an application from the gallery via Graph API Assign principal (user or group) to applicati
我发现应用程序可以在这个答案中分配给用户,但似乎无法弄清楚如何使用C#来做到这一点.下面是我正在尝试的 JSON和C#.

Azure Active Directory: assign user to an application from the gallery via Graph API

Assign principal (user or group) to application:
?resourceId is the objectId of the servicePrincipal that get created in the tenant for the application
?id is the default role id of App.
?principalId is the objectId of the principal (user or group) that is being assigned to the app.

HTTP POST https://graph.windows.net/7fe877e6-a150-4992-bbfe-f517e304dfa0/users/de4b092e-1dd4-4d40-b74d-a2d7096c9495/appRoleAssignments?api-version=1.5
Authorization : Bearer eyJ0eXAiOi--snip--JKVBfk_Q
Content-Type : application/json
Content-Length : 176
{
"id":  "fc60bc23-43df-4a60-baaa-f0b8694e0259","principalId":  "de4b092e-1dd4-4d40-b74d-a2d7096c9495","resourceId":  "93c60e8e-74f9-4add-9ae2-dd9bc0d6edcd"
}
        AppRoleAssignment appAssignment = new AppRoleAssignment();
        appAssignment.Id = appRole.Id;
        appAssignment.PrincipalId = new Guid(retrievedUser.ObjectId);
        appAssignment.ResourceId = new Guid("aa9b2f6b-6528-4552-a202-2039ce86d95c");

        appAssignment.UpdateAsync();

解决方法

派对有点晚了但是!由于文档完全缺失,我不得不做大量的谷歌搜索和跟踪&错误.

解决方案是像这样更新用户:

var appRoleAssignment = new AppRoleAssignment()
{
    ResourceId = Guid.Parse(principal.ObjectId),PrincipalId = Guid.Parse(user.ObjectId),Id = Guid.Parse(roleId)
};

user.AppRoleAssignments.Add(appRoleAssignment);
await user.UpdateAsync();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读