I'm using Microsoft Graph API to authenticate users to my web application. For SO, I have registered a test application in Registration Portal. This portal provide us application id and application secret. I have defined redirect URL which take Code and return the access token.
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);
}
My problem is bit weird. I'm able to access the token without any issues which means I have correct setup in place. However, after few calls(2) Graph API return nothing as login live dot com server not found.
I have tried cleaning cookies completely, dns cache but it didn't worked however if I restart my laptop and place a call then it seems start working. Still after few calls, Login.live.com server not found.
Please let me know your thoughts. Thanks