简体   繁体   中英

Yahoo, OAuth http request. Works on localhost but not live server

I have this code that is trying to authenticate with Yahoo! It works fine on my local sever but the same request made on my live server fails. It comes back with a (401) Unauthorized error when it calls GetResponse() . Can anyone help me understand why? Let me know if you need more information.

try
{
    string url = "https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_callback=" + Server.UrlEncode("http://www.dowdlefolkart.com/extensions/contacts/webform1.aspx");
    url = GetUrl(url, consumerKey, consumerSecret);

    var req = System.Net.HttpWebRequest.Create(url);
    using (var res = req.GetResponse().GetResponseStream())
    {
        ....
    }
}
catch (Exception ex)
{
    Response.Write("ERROR" + ex.Message);
}

Here is the full Error Exception:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. 
at System.Net.HttpWebRequest.GetResponse() 
at NopSolutions.NopCommerce.Web.Extensions.Contacts.WebForm1.Page_Load(Object sender, EventArgs e) 
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) 
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) 
at System.Web.UI.Control.OnLoad(EventArgs e) 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.HandleError(Exception e) 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest() 
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) 
at System.Web.UI.Page.ProcessRequest(HttpContext context) 
at ASP.extensions_contacts_webform1_aspx.ProcessRequest(HttpContext context) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Update:

I am getting this error with Fiddler.

oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1314119105-1314120305

So it looks like my timestamp from the live server is not correct. This is how I am creating the timestamp:

string timestamp = Math.Floor((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();

I found the issue. The reason for the error was due to an invalid timestamp. It was just slightly larger than that which was allowed. Using Fiddler i was able to determine this issue. The error was: oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1314119105-1314120305 .

I then logged onto my live server and adjusted the system clock to what it needed to be. Apparently it was 15 minutes fast. Once I adjusted this the error disappeared. Thank you @Darin Dimitrov for the assistance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM