Oauth question

Discussion in 'Shapeways API' started by 161943_deleted, May 22, 2013.

  1. Hi Everyone,

    I want to login to my account to make a browser based modeling tool and uploader. I have some trouble though getting an acces token.

    if i fill in my credentials in the consumer_key.php, I can:

    1. open <mypage>//php-curl/AuthorizeWithRequestUriQuery-oauth1-curl.php see file here

    2. i get the following reply:
    3. i can now go to
    https://api.shapeways.com/login?oauth_token=75406c2b982364998 f8a5fad61c5f14255c49a0e
    where after I log in i get a verification code

    What do I do with this verification code to proceed?

    4. if I enter it in the AuthorizeWithRequestUriQuery-oauth1-curl.php as $pin I get in return
    (i.e. null values).

    5. another try was to authenticate with <mypage>php-pecl/Authorize-oauth1-pecl.php, but then i immediatley get

    Can anyone help me with this?

    best regards,
    Tim



     
  2. Hi Tim,

    The error you're seeing with AuthorizeWithRequestUriQuery-oauth1-curl.php is because that file is prompting for input from the command line. If you provide it no input, it can't continue. The input should be the PIN you receive.

    The oauth error is because you don't have the oauth package installed. From the installation instructions here: https://github.com/Shapeways/shapeways-api/tree/master/php-p ecl you need to run 'pecl install oauth'

    Hope that helps,
    Beekey
     
  3. thanks for your help so far. II installed the Oauth module. I have some further questions though:

    1. if I open /shapeways/php-pecl/Authorize-oauth1-pecl.php in my browser I get to the readline point as well however in if I enter
    Code:
    php Authorize-oauth1-pecl.php
    in the cli I still get the "Oauth class not found" error. Does this mean it does find the class when I execute the script using the browser and but can't find it when using the cli?

    2. If I go to follow the link that the script returns I get a verifier code after login. Does this mean I authorize my own account to be accesed by the scripts that use the authentication token? is this a one time authorisation?

    3. Can the pin only be put in using CLI?

    best regards,
    Tim




     
  4. 1) CLI PHP and Apache PHP use different configurations. You have to make sure the oauth module is included in both.

    2) Yes, oauth authenticates a single user for your app per token: https://developers.shapeways.com/getting-started?li=dh_gs#aut henticate Tokens do not expire at the moment so you can use one perpetually.

    3) Yes. Our reference clients are meant to serve as an example. You are free to use as much or as little of the code as you need to develop your own application.
     
  5. how is it possible to avoid the user typing the "PIN"?
    Thanks
     
  6. The default callback in our PHP example is 'oob'. If this is passed, the user will be directed to a site with a PIN which they will need to copy/paste somewhere.

    If you provide a different callback url, Shapeways will call that url with the PIN for you to automatically process so that the user doesn't need to type anything.
     
  7. minichua
    minichua Active Member
    Hello,

    the Oauth method is really not clear to me.

    Question 1:
    - to simply upload a model , do we have to go through the whole authentification method and then use the POST request or can we use the POST directly?
    Question 2:
    - Can you give an explicit example on how to automatically callback with the PIN so that the user does not need to do anything?
    Question 3:
    - oauth, readline, consumer keys are installed on CentOS. I can not make any script work. It seems none can pass the $oauth_client = new Oauth(...) line. Do you have any tips on that? I am running CentOS 6.5.

    Sincerely.
     
    Last edited: Aug 13, 2014
  8. minichua
    minichua Active Member
    Problem solved
     
  9. Could someone please provide a sample code for auth and file-upload with the callback url method instead of the oob parameter ?
    I cannot use readline as this will be used on the browser plus there will only be one account (ours) requesting the app so we do not need multiple authentications, only one is required.

    Thank you.
     
  10. REAppTesting
    REAppTesting Member
    Can you please explain how you solved the problem?
     
  11. stonysmith
    stonysmith Well-Known Member Moderator
    >>>Could someone please provide a sample code for auth and file-upload with the callback url method instead of the oob parameter ?

    You would have to setup a web server and create a web page that will capture the pin.

    Then for the URL, you would simply specify your web page.. When you make the call to retrieve the PIN, your webpage will be accessed with a form similar to this:
    http://www.mywebsite.com/mypinpage.pyp?PIN=339484

    Your page would need to receive that request, process the parameter, and save the pin# off for later use.
     
  12. dmorley123
    dmorley123 Member
    As I understand it, Shapeways uses OAuth1. If I utilize an OAuth2 class, will it still work?
     
  13. stonysmith
    stonysmith Well-Known Member Moderator
    No. The two classes work entirely differently. At this time, you must use the OAuth1
     
  14. dmorley123
    dmorley123 Member
    Thanks for your reply. I do not manage my server so I can't install php services. Can you suggest a php-source-code Oauth1 class?
     
  15. stonysmith
    stonysmith Well-Known Member Moderator
    I wish I could, but I'm not a php expert.