Azure active directory 从文件中存储的令牌获取MSAL令牌

Azure active directory 从文件中存储的令牌获取MSAL令牌,azure-active-directory,openid-connect,msal,bearer-token,Azure Active Directory,Openid Connect,Msal,Bearer Token,我已将初始用户takencache保存在一个文件中。现在,当我想获取AcquireTokenSilent时,我不知道如何使用保存的令牌缓存,因为我找到的所有文档都是基于缓存使用的,而不是用于其他内存格式 我已经搜索了微软MSAL回购协议的数量,但他们没有提供任何解决方案的帮助 IConfidentialClientApplication app = MsalAppBuilder.BuildConfidentialClientApplication(); Authenti

我已将初始用户takencache保存在一个文件中。现在,当我想获取AcquireTokenSilent时,我不知道如何使用保存的令牌缓存,因为我找到的所有文档都是基于缓存使用的,而不是用于其他内存格式

我已经搜索了微软MSAL回购协议的数量,但他们没有提供任何解决方案的帮助

 IConfidentialClientApplication app = MsalAppBuilder.BuildConfidentialClientApplication();
            AuthenticationResult result = null;
            StreamReader sr = new StreamReader("D:\\Test.txt");
            string line = sr.ReadLine();

                var accounts = await app.GetAccountsAsync();
            string[] scopes = { "Mail.Read" };


            try
            {
                // try to get token silently
                result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault()).ExecuteAsync().ConfigureAwait(false);
            }
            catch (MsalUiRequiredException)
            {
                ViewBag.Relogin = "true";
                return View();
            }
            catch (Exception eee)
            {
                ViewBag.Error = "An error has occurred. Details: " + eee.Message;
                return View();
            }

            if (result != null)
            {
                // Use the token to read email
                HttpClient hc = new HttpClient();
                hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", result.AccessToken);
                HttpResponseMessage hrm = await hc.GetAsync("https://graph.microsoft.com/v1.0/me/messages");

                string rez = await hrm.Content.ReadAsStringAsync();
                ViewBag.Message = rez;
            }

到底是什么不起作用?实际上,我正在将accessToken存储在文件中,因此我无法从await app.GetAccountsAsync()检索数据,因为它只从缓存中获取数据,所以我不知道该怎么做。调用您提供的graph api时需要该令牌。AcquireTokenSilent在内部为令牌创建一个缓存并使用它(请参阅)——您不必担心这样做。据我所知,你的代码是正确的?