使用 Microsoft.Identity 与 Azure.Identity 对 Microsoft Graph 的守护进程调用
Daemon call to Microsoft Graph with Microsoft.Identity vs Azure.Identity
使用 Azure.Identity 而不是 Microsoft.Identity.Client 或 Microsoft.Identity.Web 来调用 Microsoft Graph 是否存在问题或缺点?
我正在尝试使用 asp.net 核心 3.1 MVC webapp 来访问 Sharepoint 上的日历列表,而无需用户登录。
我使用应用程序权限 Sites.Selected 在 Azure 中注册了该应用程序,并做了管理员 post 的事情以获得对特定站点的读取权限...
我发现这个控制台示例运行良好:
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 以获得我正在寻找的特定信息)
这看起来太容易了..这样做一定有问题吗?
没有什么可担心的。事实上,您应该更喜欢使用 Azure.Identity 包,因为它较新。使用新包,开发人员可以更轻松地生成访问令牌。在后台,Microsoft 仍然使用 ConfidentialClientApplicationBuilder,您可以通过检查 source code and drilling down into the class MSALConfidentialClient 来检查自己。基本上复杂度没变,现在由微软管理。
使用 Azure.Identity 而不是 Microsoft.Identity.Client 或 Microsoft.Identity.Web 来调用 Microsoft Graph 是否存在问题或缺点?
我正在尝试使用 asp.net 核心 3.1 MVC webapp 来访问 Sharepoint 上的日历列表,而无需用户登录。
我使用应用程序权限 Sites.Selected 在 Azure 中注册了该应用程序,并做了管理员 post 的事情以获得对特定站点的读取权限...
我发现这个控制台示例运行良好: 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 以获得我正在寻找的特定信息)
这看起来太容易了..这样做一定有问题吗?
没有什么可担心的。事实上,您应该更喜欢使用 Azure.Identity 包,因为它较新。使用新包,开发人员可以更轻松地生成访问令牌。在后台,Microsoft 仍然使用 ConfidentialClientApplicationBuilder,您可以通过检查 source code and drilling down into the class MSALConfidentialClient 来检查自己。基本上复杂度没变,现在由微软管理。