Microsoft Graph SDK - Login(Microsoft Graph SDK - 登录)
问题描述
是否可以使用 MS Graph 仅登录一次?目前,每当我调用 graphServiceClient 时,它都会要求我登录或选择登录用户.有什么办法可以避免选择登录用户的过程?提前致谢.
Is it possible to only log in once using MS Graph? Currently whenever I call the graphServiceClient it will ask me to sign in or to choose the signed in user. Is there any way that the process of choosing the signed in user can be avoided? Thanks in advance.
目前这是我初始化 graphService 的方式.
Currently this is how I initialize the graphService.
public static GraphServiceClient GetAuthenticatedClient()
{
GraphServiceClient graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
string appID = ConfigurationManager.AppSettings["ida:AppId"];
PublicClientApplication PublicClientApp = new PublicClientApplication(appID);
string[] _scopes = new string[] { "Calendars.read", "Calendars.readwrite" };
AuthenticationResult authResult = null;
authResult = await PublicClientApp.AcquireTokenAsync(_scopes); //Opens Microsoft Login Screen
// Append the access token to the request.
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", authResult.AccessToken);
}));
return graphClient;
}
现在,每当我使用标准 SDK 功能时,它都会要求我登录:
等待 graphClient.Me.Events[testID].Request().UpdateAsync(x);
然后当我使用其他功能时它会再次询问我:
等待 graphClient.Me.Events.Request().AddAsync(newEvent);
推荐答案
是的,这是可能的.AcquireTokenAsync 总是触发登录.相反,您需要实现令牌缓存并使用 AcquireTokenSilentAsync.https://docs.microsoft.com/en-us/outlook/rest/dotnet-tutorial 有一个 web 应用示例.
Yes it is possible. AcquireTokenAsync does always trigger logon. Instead, you need to implement a token cache and use AcquireTokenSilentAsync. https://docs.microsoft.com/en-us/outlook/rest/dotnet-tutorial has a web app example.
这篇关于Microsoft Graph SDK - 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Microsoft Graph SDK - 登录
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
