Microsoft Graph SDK-登录 [英] Microsoft Graph SDK - Login

查看:146
本文介绍了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/zh-cn/outlook/rest/dotnet-tutorial 有一个网络应用程序示例.

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-登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆