如何使用 Microsoft Graph 服务客户端选择缓存的凭据
How to choose cached credential with Microsoft Graph Service Client
我有 MSAL 身份客户端应用程序,可以用来获取用户的访问令牌。
我现在正尝试使用 Microsoft.Graph.Auth
来发送请求。下面的代码显示了如何将 MSAL IndentityClientApp
传递给 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);
}));
我有 MSAL 身份客户端应用程序,可以用来获取用户的访问令牌。
我现在正尝试使用 Microsoft.Graph.Auth
来发送请求。下面的代码显示了如何将 MSAL IndentityClientApp
传递给 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);
}));