【发布时间】:2021-12-18 04:32:42
【问题描述】:
使用 Azure.Identity 而不是 Microsoft.Identity.Client 或 Microsoft.Identity.Web 来调用 Microsoft Graph 是否存在问题或劣势?
我正在尝试做 asp.net core 3.1 MVC webapp 来访问 sharepoint 上的日历列表,而无需用户登录。
我在 Azure 中注册了应用程序权限 Sites.Selected 的应用程序,并做了管理员发布的事情以获得对特定站点的读取权限...
我发现这个控制台示例运行良好: https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2/tree/master/1-Call-MSGraph 它使用 Microsoft.Identity.Client 并且有一些代码..
我一直在寻找其他方法,并找到了一些使用 Microsoft.Identity.Web 的示例,我只测试了委托,但我认为它可以在没有用户登录的情况下工作。
然后我找到了一个使用 Azure.Identity 的示例,它只需要很少的代码...
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential);
var result = graphServiceClient.Sites[siteId]
.Lists[listId]
.Items
.Request(queryOptions)
.GetAsync().Result;
(queryOptions 只是展开 select filter orderby 以获取我正在寻找的特定信息)
这似乎太容易了..这样做一定有什么问题吗?
【问题讨论】:
-
我认为它也很好。没有错。
标签: c# azure asp.net-core microsoft-graph-api