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 - 登录
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
