Dalam kode di bawah ini saya berhasil mengambil token penyegaran dari alamat email [email protected]. Namun, ketika saya mencoba masuk dengan [email protected], ia tidak memberikan token penyegaran, melainkan mengembalikan respons ini.
Tanggapan:
{
"error": "invalid_grant",
"error_description": "AADSTS70000: The provided value for the 'code' parameter is not valid. The code has expired.\r\nTrace ID: ...\r\nCorrelation ID: ...\r\nTimestamp: 2016-05-19 10:13:05Z",
"error_codes": [
70000
],
"timestamp": "2016-05-19 10:13:05Z",
"trace_id": "8cceb393-....",
"correlation_id": "5227de8...."
}
Kode:
private async Task<string> GetRefreshRoken(string authCode, string onSuccessRedirectUri) {
var client = new HttpClient();
var parameters = new Dictionary<string, string>
{
{"client_id", _clientId},
{"client_secret", _clientSecret},
{"code",authCode }, // what retreived from //https://login.microsoftonline.com/common with authroization.
{"redirect_uri", onSuccessRedirectUri}, //http://localhost:27592/Home/Authorize
{"grant_type","authorization_code" }
};
var content = new FormUrlEncodedContent(parameters);
var response = await client.PostAsync("https://login.microsoftonline.com/common/oauth2/v2.0/token", content);
var tokensJsonString = await response.Content.ReadAsStringAsync();
dynamic token = Newtonsoft.Json.JsonConvert.DeserializeObject(tokensJsonString);
return token.refresh_token;
}
Jadi saya mencari di Google dengan nomor kesalahan dan menemukan http://www.matvelloso.com/2015/01/30/troubleshooting-common-azure-active-directory-errors/ halaman yang menjelaskan kesalahan:
Kemudian saya mengubah url pengalihan saya menjadi "http://localhost:27592/Home/Authorize/ ". Karena saya menggunakan https://dev.outlook.com/restapi/tutorial/dotnet tutorial sebagai referensi, sekarang saya tidak bisa login dengan akun lain.
Apakah ada pendekatan yang baik untuk mengambil token penyegaran untuk akun Outlook?