Question

I'm trying to update token, but I get error "The remote server returned an error: (400) Bad Request." My code is:

public static object Refresh_token(string client_id, string redirect_uri, string client_secret, string refresh_token, string scope)
{
    var requestUrl = new StringBuilder("https://login.live.com/oauth20_token.srf");
    requestUrl.Append("?grant_type=refresh_token");
    requestUrl.AppendFormat("&client_id={0}", client_id);
    requestUrl.AppendFormat("&redirect_uri={0}", HttpUtility.UrlEncode(redirect_uri));
    requestUrl.AppendFormat("&client_secret={0}", HttpUtility.UrlEncode(client_secret));
    requestUrl.AppendFormat("&refresh_token={0}", refresh_token);       

    WebRequest request = HttpWebRequest.Create(requestUrl.ToString());
    request.Method = "GET";       
    request.ContentType = "application/x-www.form-urlencoded;charset=UTF-8";
    WebResponse response = request.GetResponse();

    using (var reader = new StreamReader(response.GetResponseStream()))
    {
        var json = reader.ReadToEnd();
        return JsonConvert.DeserializeObject<Offline_access>(json);
    }
}

If I send it from browser I get

{"error":"invalid_scope","error_description":"The provided request must include a 'scope' input parameter."}

I tried to do it with POST, but it was the same problem. Have some ideas?

Était-ce utile?

La solution

Seems like the spec changed on the web server side and it's expecting you to send a scope parameter. I don't know what the scope parameter is and what you need to supply to it but essentially you'll need to add a line for the requestUrl to add it.

requestUrl.AppendFormat("&scope={0}", {whatever value the scope is suppose to be}); 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top