Microsoft OAuth does not return refresh_token
本文关键字:refresh token return not OAuth does Microsoft | 更新日期: 2023-09-27 18:29:09
33I向Microsoft发出以下请求以获取AuthCode,
public ActionResult ConnectMicrosoft()
{
var ClientId = "xxxxxxxxx";
// var ClientSecret = "xxxxxxxxxxxxxxx";
var RedirectUri = "http://www.domain.com:50952/Settings/MicrosoftAuthCallback";
var MsUrl = String.Format("https://login.live.com/oauth20_authorize.srf?client_id={0}&scope=wl.basic&response_type=code&redirect_uri={1}", ClientId, RedirectUri);
return Redirect(MsUrl);
}
在回叫时,
public ActionResult MicrosoftAuthCallback(string code)
{
string result = null;
var ClientId = "xxxxxxxxxxxx";
var ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxx";
var RedirectUri = "http://www.domain.com:50952/Settings/MicrosoftAuthCallback";
var FinalUri = String.Format("https://login.live.com/oauth20_token.srf?client_id={0}&client_secret={1}&code={2}&grant_type=authorization_code&redirect_uri={3}", ClientId, ClientSecret, code, RedirectUri);
HttpWebRequest _Request = HttpWebRequest.Create(FinalUri) as HttpWebRequest;
_Request.Method = "GET";
using (WebResponse _Response = _Request.GetResponse())
{
var sr = new StreamReader(_Response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
}
var _Serializer = new JavaScriptSerializer();
var TokenData = _Serializer.Deserialize<MicrosoftToken>(result);
return View();
}
回调方法成功返回access_token、tokentype和expires_in以及authentication_token,但缺少刷新令牌。你能告诉我我做错了什么吗?
嗯,忘记包括作用域wl.offline_access,还请求必须使用ContentType="application/x-wwww-form-urlencoded"进行POST