Oauth Parameters In Url Stopped Working - In Headers Work Fine

Discussion in 'Shapeways API' started by Sailcharger, Sep 14, 2016.

Anyone else had this problem?

  1. Yes

    3 vote(s)
    100.0%
  2. No

    0 vote(s)
    0.0%
  3. Not sure

    0 vote(s)
    0.0%
  1. Sailcharger
    Sailcharger Member
    Problem:
    After a year of using C# code from the Shapeways recommended .NET API Example no API calls worked. Using oauth parameters in the url not even the first simple access to GET /oauth1/request_token/v1 worked anymore. It returned "authorization error".

    After lots of testing I switched to the oauth variant storing parameters in the an HTTP header variable "Authorization" instead.

    Have not yet figured out what had deteriorated in my code as it uses the underlaying oauth DLL from the sample and it is not rocket science.

    Solution - Change to header based oauth:
    To fix it, for anyone interested, in my client C# code I added a method that returns a HttpWebRequest instance that can take either form - url or header based. The sample contains an oauth call to https://api.shapeways.com/models/v1 just to demonstrate how the HttpWebRequest is used :

    Code:
    //Oauth parameters storage alternatives in HTTP request
    public enum par_location {header, url}
    
    //Store oauth parameters in header as default
    public par_location oauth_par_location = par_location.header;
    
    //Return HttpWebRequest with either header or url based parameters
    private HttpWebRequest createHttpWebRequest(OAuthRequest client)
    {
        HttpWebRequest request = null;
        var url = client.RequestUrl;
    
        switch (this.oauth_par_location)
        {
            case par_location.header:
                request = (HttpWebRequest)WebRequest.Create(url);
                request.Headers["Authorization"] = client.GetAuthorizationHeader();
                break;
            case par_location.url:
    
                url += "?" + client.GetAuthorizationQuery();
                request = (HttpWebRequest)WebRequest.Create(url);
                break;
        }
    
        return request;
    }
    
    
    //Demo - Obtain model list
    public object getModels() {
    OAuthRequest client = new OAuthRequest() {
      Method = "GET",
       Type = OAuthRequestType.ProtectedResource,
       SignatureMethod = OAuthSignatureMethod.HmacSha1,
       ConsumerKey = this.consumerKey,
       ConsumerSecret = this.consumerSecret,
       RequestUrl = "https://api.shapeways.com/models/v1",
       Version = "1.0a",
       Realm = "shapeways.com",
       TokenSecret = this.OAuthSecret,
       Token = this.OAuthToken,
    };
    
    HttpWebRequest request = this.createHttpWebRequest(client);
    
    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
    return JsonConvert.DeserializeObject(content);
    }
    


    Great it works - Problem solved - But why did it stop working?

    Once all my code was changed to initiate the HttpWebResponse with oauth params in the HTTP header all vent back to normal.

    Strange..


    o_O
     
    Last edited: Sep 14, 2016
  2. Actually another symptom of this is that the
    AuthorizeWithRequestUriQuery-oauth1-curl.php script that uses the URL method does not work anymore either. While the
    Authorize-oauth1-pecl.php script that uses the Authorization header still works fine. Is the non-header version not going to be supported anymore? Or is it just a temporary issue?