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,但缺少刷新令牌。你能给我一些关于我做错的线索吗?
答案 0 :(得分:1)
呵呵,忘了包括范围,wl.offline_access,还请求必须使用ContentType =&#34; application / x-www-form-urlencoded&#34;