【Azure Developer】如何用Microsoft Graph API管理AAD Application里面的Permissions
问题描述
如何用Microsoft Graph API给应用添加Microsoft Graph Application Permission
解决方法
一:首先获取Microsoft Graph Application Permission对应的唯一标识GUID
- 00000003-0000-0000-c000-000000000000是Microsoft Graph API对应的AppId。
- 以Directory.Read.All权限为例,在appRoles中查找权限Directory.Read.All的这项,其中id则是Directory.Read.All的唯一标识。
二:调用Microsoft Graph Update Application接口更新requiredResourceAccess参数
{ "requiredResourceAccess": [ { "resourceAppId": "00000003-0000-0000-c000-000000000000", "resourceAccess": [ { "id": "e1fe6dd8-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "type": "Scope" },{ "id": "7ab1d382-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "type": "Role" } ] } ] } |
注:给应用添加Microsoft Graph Delegated Permission,需要在第一步中查找oauth2PermissionScopes中对应的权限Directory.Read.All并且找到对应的id,把第二步中的标黄的type的值修改为Scope,并且把id的值替换掉。
三:如果在第一步获取的权限需要管理员同意,则需要管理员在门户中授予同意,可以通过第一步中获取的权限中的type来区分,如果type是Admin则代表需要管理员同意。
参考内容
- 给应用添加APIs My organization uses的权限,在第一步执行查询唯一标识时需要根据该应用id来查询,参考如下,查找的结果中oauth2PermissionScopes里的权限对应Scope( Delegated Permission),appRoles里的权限对应Role(Application Permission)
https://microsoftgraph.chinacloudapi.cn/v1.0/servicePrincipals?$search="appId:yourclientid"
Update Application:https://docs.microsoft.com/zh-cn/graph/api/application-update?view=graph-rest-1.0&tabs=http
List servicePrincipals:https://docs.microsoft.com/zh-cn/graph/api/serviceprincipal-list?view=graph-rest-1.0&tabs=http
requiredResourceAccess:https://docs.microsoft.com/zh-cn/graph/api/resources/requiredresourceaccess?view=graph-rest-1.0
- 对于Azure Service Management API和Microsoft Graph API的App Id都是可以从List servicePrincipals中查找到的,建议从接口中查找,以免发生变更时影响使用。比如:
https://microsoftgraph.chinacloudapi.cn/v1.0/servicePrincipals?$search="displayName:Microsoft Graph"&$count=true
https://microsoftgraph.chinacloudapi.cn/v1.0/servicePrincipals?$search="displayName:Azure Service Management"&$count=true
- user_impersonation的id首先通过上述接口获取到的结果中找到Azure Service Management,也可以在这里找到它对应的user_impersonation的id。
List servicePrincipals:https://docs.microsoft.com/zh-cn/graph/api/serviceprincipal-list?view=graph-rest-1.0&tabs=http
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?