Login.live.com服务器未找到错误

时间:2017-09-14 19:36:19

标签: c# asp.net-core windows-10 microsoft-graph service-fabric-stateless

我正在使用Microsoft Graph API对我的Web应用程序的用户进行身份验证。对于SO,我在Registration Portal注册了一个测试应用程序。此门户为我们提供应用程序ID和应用程序密我定义了redirect URL,它接受​​Code并返回访问令牌。

 public async Task<AuthToken> ExchangeCodeForAccessToken(string code)
    {
        MicrosoftGraphTokenResponse tokenResponse = null;
        using (HttpClient client = new HttpClient())
        {
            var postFormParameters = new List<KeyValuePair<string, string>>()
            {
                    new KeyValuePair<string, string>("client_id", _msGraphpParameter.AppId),
                    new KeyValuePair<string, string>("redirect_uri", _msGraphpParameter.RedirectUrl),
                    new KeyValuePair<string, string>("code", code),
                    new KeyValuePair<string, string>("grant_type", "authorization_code"),
                    new KeyValuePair<string, string>("scope", _msGraphpParameter.Scopes)
            };

            if (_msGraphpParameter.AppSecret != null)
            {
                // Secret isn't needed for client apps
                postFormParameters.Add(new KeyValuePair<string, string>("client_secret", _msGraphpParameter.AppSecret));
            }

            var formContent = new FormUrlEncodedContent(postFormParameters);
            client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", TokenRefreshContentType);

            HttpResponseMessage response = await client.PostAsync(MsGraphTokenRefreshUrl, formContent);
            string responseString = await response.Content.ReadAsStringAsync();
            tokenResponse = JsonConvert.DeserializeObject<MicrosoftGraphTokenResponse>(responseString);

        }
        return TransformMSGraphTokenResponseIntoAuthProperties(tokenResponse);
    }

我的问题有点奇怪。我能够在没有任何问题的情况下访问令牌,这意味着我已经有了正确的设置。但是,在几次调用之后(2)Graph API没有返回任何内容,因为找不到login live dot com 服务器。

我已经尝试完全清理cookie,dns缓存但它没有用,但是如果我重新启动笔记本电脑并拨打电话,那么它似乎开始工作了。仍然在几次通话后,找不到Login.live.com服务器。

这是快照enter image description here

请让我知道你的想法。感谢

0 个答案:

没有答案
相关问题