c# - 如何使用 Microsoft Graph 服务客户端选择缓存凭据
问题描述
我有 MSAL 身份客户端应用程序,可用于获取用户的访问令牌。
我现在正尝试使用它Microsoft.Graph.Auth
来发送请求。下面的代码显示了如何将 MSALIndentityClientApp
传递给Graph.Auth
.
DeviceCodeProvider authProvider = new DeviceCodeProvider(IdentityClientApp, Scopes);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
如果缓存了多个凭据,我无法确定如何指定要使用的缓存凭据。
当我单独使用 MSAL 时,我使用下面的代码来指定用户帐户。如何使用 MS.Graph 做到这一点?
authResult = await IdentityClientApp.AcquireTokenSilent(Scopes, account).ExecuteAsync();
解决方案
使用这种方法创建GraphClient
允许我控制使用的帐户:
GraphServiceClient graphClient = new GraphServiceClient(MSGraphURL, new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", OutlookToken);
}));
推荐阅读
- python - Django 测试,断言 CSV 内容存在
- php - 在 Wordpress 网站上显示最后修改日期
- ckeditor - CKEditor 中的只读部分
- sql - 带有插入语句的 CTE
- node.js - Node.js - 变量范围和垃圾收集
- c# - EPPlus 是否需要在服务器上安装 Excel?
- android - 如何从头开始发出 HTTP 请求的基础知识,可用于 Oauth 和不同的 api 调用
- c++ - 如何隐式加载仅签名的 DLL
- python - Pandas:基于三个不同的其他列值求和和聚合列值
- kubernetes - 带有 readynessprobe 的 helm 部署