Home » Developers » Shapeways API » HTTP_OAuth?
Search Search  
Show: Today's Messages    Show Polls    Message Navigator
HTTP_OAuth? [message #72306] Sun, 28 July 2013 22:08 UTC Go to next message
avatar roseEq  is currently offline roseEq
Messages: 4
Registered: July 2013
Go to all my models
Junior Member
Hi,

Is it possible to use HTTP_OAuth with the api? I have a server that can't instal oath extension and have been trying the pear version instead. It seems to be fine with all the GET calls (materials etc) but POST always returns and invalid signature. I am guessing it has to do with the encoding of the json string and how parameters are passed...


try {
$oauth = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret,$access_token,$access_secret);
} catch (OAuthException2 $e){
var_dump($e);
}


try {
$filename = "cube-1cm3-centered_in_meter.stl";
$file = file_get_contents($filename);
$data = array('fileName' => $filename,
'file' => rawurlencode(base64_encode($file)),
'hasRightsToModel' => 1,
'acceptTermsAndConditions' => 1,
);
$data_string = array(json_encode($data));
$response = $oauth->sendRequest("http://api.shapeways.com/model/v1", $data_string);
var_dump($response->getBody());

} catch (OAuthException2 $e){
var_dump($e);
}
Re: HTTP_OAuth? [message #72536 is a reply to message #72306 ] Fri, 02 August 2013 07:49 UTC Go to previous messageGo to next message
avatar bartv  is currently offline bartv
Messages: 1670
Registered: December 2007
Go to my shop
Senior Member
Hi,

our API expert is on a short break this week - he'll return next week and he'll get back to you then.

Cheers,

Bart


Community Manager Europe | Shapeways
Re: HTTP_OAuth? [message #72656 is a reply to message #72306 ] Mon, 05 August 2013 13:53 UTC Go to previous messageGo to next message
avatar ProfessorBeekums  is currently offline ProfessorBeekums
Messages: 25
Registered: February 2013
Go to my shop
Junior Member
I work here
Hi,

I'm not familiar with that oauth library, but you should be able to use any library that fully supports oauth1. Is there a way for HTTP_Oauth to define the method you're using? I don't see that in the code sample you posted and the generated signature is affected by whether your request is a POST or a GET.

-Beekey
Re: HTTP_OAuth? [message #72657 is a reply to message #72656 ] Mon, 05 August 2013 13:54 UTC Go to previous messageGo to next message
avatar ProfessorBeekums  is currently offline ProfessorBeekums
Messages: 25
Registered: February 2013
Go to my shop
Junior Member
I work here
Also, why are you unable to install the oauth extension on your server?
Re: HTTP_OAuth? [message #72820 is a reply to message #72306 ] Thu, 08 August 2013 15:21 UTC Go to previous messageGo to next message
avatar mattermaster  is currently offline mattermaster
Messages: 5
Registered: August 2013
Go to all my models
Junior Member
I'm also running into the signature invalid error ONLY when making POST requests. I'm using a popular python OAuth library called rauth.
Re: HTTP_OAuth? [message #73973 is a reply to message #72656 ] Fri, 30 August 2013 18:25 UTC Go to previous messageGo to next message
avatar roseEq  is currently offline roseEq
Messages: 4
Registered: July 2013
Go to all my models
Junior Member
Hi,

By default the library's sendRequest function uses POST but I also tried passing in the POST specifcally with the same result:

$response = $oauth->sendRequest("http://api.shapeways.com/model/v1", $data_string, 'POST');

As I said the library does work with GET requests because I was able to retrieve the token and pin etc using it but not sending a post request. I discovered that if I pass in the $data_string without the json encoding it says:
Field <file> is required, but missing.\nField <fileName> is required, but missing.

With json encoding it returns a signature error... It cannot figure out how to properly create a paramater for the function that works.

I was not able to install the oauth extension because I have a shared server and can't access it as root/admin.

thanks
Re: HTTP_OAuth? [message #73974 is a reply to message #73973 ] Fri, 30 August 2013 18:44 UTC Go to previous messageGo to next message
avatar ProfessorBeekums  is currently offline ProfessorBeekums
Messages: 25
Registered: February 2013
Go to my shop
Junior Member
I work here
Can you provide a link to the documentation for the library you're using? It seems like it may not be generating the signature correctly on a POST request.

-Beekey
Re: HTTP_OAuth? [message #73978 is a reply to message #73974 ] Fri, 30 August 2013 20:24 UTC Go to previous messageGo to next message
avatar roseEq  is currently offline roseEq
Messages: 4
Registered: July 2013
Go to all my models
Junior Member
The documentation can be found here:
http://pear.php.net/package/HTTP_OAuth/docs/latest/

Thanks for checking it out!
Re: HTTP_OAuth? [message #74436 is a reply to message #73978 ] Sun, 08 September 2013 20:50 UTC Go to previous messageGo to next message
avatar aaal  is currently offline aaal
Messages: 2
Registered: September 2013
Go to all my models
Junior Member
Hi roseEQ,

Not sure if you're still having this problem, but I ran into a similar problem and just wanted to share my findings. I'm using the Python oauth2 library. I got the same "field is missing" errors when performing a POST request and json encoding the parameters. I got around the problem by setting this header:

Content-Type: application/json

After that, I got a response that details the spec for the API endpoint, but not the actual data I was requesting (I was hitting /price/v1). I haven't been able to get past this, but hopefully this helps you a little bit.
Re: HTTP_OAuth? [message #74466 is a reply to message #72306 ] Mon, 09 September 2013 14:29 UTC Go to previous messageGo to next message
avatar ProfessorBeekums  is currently offline ProfessorBeekums
Messages: 25
Registered: February 2013
Go to my shop
Junior Member
I work here
roseEQ,

I haven't been able to find much on the problem with the pear version of oauth other than this old bug: http://pear.php.net/bugs/bug.php?id=16782 which looks like it caused GET requests to fail. Can you check the version of that oauth library that's being used?

Can you talk to your server's admin on getting the pecl oauth client installed? Some initial searching on Google shows a few other people who have had problems with the pear version and fixed them by switching.

aaal,

The Shapeways API runs on Oauth, not Oauth2. You need to use a library that supports Oauth. For python, I've found requests_oauthlib to be reliable.

Thanks,
Beekey
Re: HTTP_OAuth? [message #74622 is a reply to message #74466 ] Thu, 12 September 2013 01:36 UTC Go to previous messageGo to next message
avatar aaal  is currently offline aaal
Messages: 2
Registered: September 2013
Go to all my models
Junior Member
Hi Beekey, OAuth2 is just the library name but it does support oauth version 1.0. However, I tried requests-oauthlib per your suggestion and I got that to work. Thanks!
Re: HTTP_OAuth? [message #84222 is a reply to message #74622 ] Sun, 02 February 2014 16:33 UTC Go to previous messageGo to next message
avatar archipelis  is currently offline archipelis
Messages: 1
Registered: May 2011
Go to my shop
Junior Member
Hi all,

I confirm the problem:

I got this result:

string(425) "{"result":"failure","reason":"Authentication Error","oauth_error_message":" oauth_problem=signature_invalid&debug_sbs=POST&http% 3A%2F%2Fapi.shapeways.com%2Fmodel%2Fv1&oauth_consumer_ke y%blabla%26oauth_nonce%blabla%26oauth_signature_method%3DHMA C-SHA1%26oauth_timestamp%3Dblabla3%26oauth_token%3Dblabla%26 oauth_version%3D1.0 "}"


I also confirm that HTTP_OAuth is implementing OAuth 1.0
Is there another solution?

Thanks
Seb


Re: HTTP_OAuth? [message #84350 is a reply to message #72306 ] Tue, 04 February 2014 15:55 UTC Go to previous message
avatar mattermaster  is currently offline mattermaster
Messages: 5
Registered: August 2013
Go to all my models
Junior Member
For those of you still trying to figure out this problem and who are using python, I managed to get it to work using the Requests-OauthLib library. I can go through the whole verification "handshake" and make POST and GET requests without any issues. Hope that helps!

[Updated on: Tue, 04 February 2014 15:56 UTC]


 
   
Previous Topic:Models that used to work are now "Not for sale"
Next Topic:Get existing shop data?