Md.*_*rim 2 outlook oauth access-token oauth-2.0 office365
在下面的代码中,我可以从 email@company.com 电子邮件地址成功检索刷新令牌。但是,当我尝试使用 email@outlook.com 登录时,它不会提供刷新令牌,而是返回此响应。
回复:
{
"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...."
}
Run Code Online (Sandbox Code Playgroud)
代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
所以我用谷歌搜索了错误号并找到了http://www.matvelloso.com/2015/01/30/troubleshooting-common-azure-active-directory-errors/错误描述的页面:

然后我将重定向 url 更改为“ http://localhost:27592/Home/Authorize/ ”。由于我使用这个https://dev.outlook.com/restapi/tutorial/dotnet教程作为参考,现在我无法使用任何其他帐户登录。
有什么好的方法可以检索 Outlook 帐户的刷新令牌吗?
对于 windows live id 帐户,当两次使用授权码时,您将收到错误“ The provided value for the 'code' parameter is not valid. The code has expired. ”。
刷新令牌的正确方法是使用刷新令牌(v2.0 令牌参考 > 刷新令牌)。
首先,确保您已声明范围“offline_access”。
然后,您将在使用 grant_type=code 获取令牌时获得 access_token(第一次获取令牌)。
接下来,您需要使用 grant_type=refresh_token 来刷新您的访问令牌。
| 归档时间: |
|
| 查看次数: |
3951 次 |
| 最近记录: |