【发布时间】:2020-02-11 07:05:20
【问题描述】:
我正在尝试通过从 Microsoft Graph API 接收组信息来获得授权。
(https://docs.microsoft.com/en-us/graph/api/user-list-memberof?view=graph-rest-1.0&tabs=http)
所以,基本上,在 asp.net MVC Web API 控制器项目中,我有产品控制器,它会将以下数据返回到 Angular 客户端,并将显示在下拉列表中
[
{id: "864", text: "Sports", name: "145028", type: null, description: ""},
{id: "593", text: "Beauty", name: "111111", type: null, description: ""},
{id: "616", text: "Home", name: "33000D", type: null, description: ""},
]
现在,我想根据用户组分配隐藏此产品信息,例如,如果用户有以下组分配,那么只有运动项目应该可见。
"id": "864-Sport",
{
"value": [
{
"@odata.type": "#microsoft.graph.group",
"id": "864-Sport",
"createdDateTime": null,
"description": "All users at the company",
"displayName": "All Users",
"groupTypes": [],
"mailEnabled": false,
"securityEnabled": true,
}
]
}
为了实现这一点,我计划做以下事情。
Que#1:现在我不确定黄色框是否突出显示,如何将我的组信息对象用于我拥有的所有控制器(大约 25 个)?在考虑 RESTful API 指南时。
Que#2:或者你如何以更好的方式实现这一目标?如果我的方法是错误的?,我打算在服务器端做,因为将来如果我们有更多的客户端(比如说移动应用程序),它将支持这一点。
Que3:在服务器端而不是客户端获取令牌是个好主意吗?
提前致谢。
【问题讨论】:
-
我不确定如何处理突出显示的黄色框。但是如果你需要做基于组的授权,你可以利用
groupMembershipClaims。您无需调用 Microsoft Graph API 即可获取组信息。修改应用清单中的“groupMembershipClaims”字段后,令牌将包含组的 Id,然后您可以实现您的授权逻辑。见stackoverflow.com/questions/58517463/…。 -
好吧,我必须使用 micrsoft graph api,因为从那里调用“memberof”我们将设置组信息
标签: c# angular authentication asp.net-web-api azure-active-directory