Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Options

oauth what is it?

billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
edited January 2018 in App Store & Partners Apps


oauth video



I can do this in 5 lines of code. I'll post the code later.

Comments

  • Options
    billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited January 2018
    An Onshape app requires something called oauth to allow your website to talk to their servers. Here's the oauth code used on my new site. To see this work, cut the url address below and paste it into your browser.

    1. It starts with the web address and in my case its:
    https://rndengineering.com/pro/


    2. There's no parameters sent in this address so I capture this and send the user to onshape. Here's the code that checks for parameters and re-locates to onshape:
     
    //handle oauth code, no code?, go get it<br>if (!$_REQUEST["code"])&nbsp;&nbsp; <br>echo '<script>location = "https://oauth.onshape.com/oauth/authorize?response_type=code&client_id=DZ3JRO3ECFWZY7ZVY%3D";</script>';


    3. This sends the user off to Onshape so they can allow the user to sign in. Upon success, they'll send the user back to my site base on a url return address I registered in the app store. Here's the updated address Onshape sends back:

    https://rndengineering.com/pro/?code=vfmAcpHiNkFRkl

    The url address above won't work if you copy it into a browser, it's a deadend and goes nowhere, timed out. Notice that Onshape adds a code to the url.


    4. With a code returned from Onshape, I request a token from Onshape:
    <div>//have code so process<br></div><div>$token="curl -X POST -H \"Content-Type:application/x-www-form-urlencoded\" -d \"grant_type=authorization_code&code=$_REQUEST["code"]&client_id=DZ3JROH7SNRVW2Y7ZVY%3D&client_secret=C2A2VUGAHV4H2XM5SNEC5VQ%3D%3D%3D%3D\"&nbsp; \"https://oauth.onshape.com/oauth/token\" ";<br></div>

    The ultimate piece of information, the reason for all this interaction is inside $token.

    5. Grab the 'access_token'. It's needed for all subsequent calls to Onshape servers and it only lasts for 60 minutes. Get the access token:

    //yeah just what I need<br>$token['access_token']


    Here's a video link to my latest code:
    R&D pro release candidate


  • Options
    bruce_williamsbruce_williams Member, Developers Posts: 842 PRO
    @billy2

    Thanks for the app! Looks really useful.  Lack of display states & better property management has been a big deal for adoption of OS by my engineers.  Will look forward to your next releases and in meantime I am going to start testing it out.  
    www.accuratepattern.com
  • Options
    billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    Thanks Bruce, let me know what you find.


  • Options
    alan_baljeualan_baljeu Member, User Group Leader Posts: 111 ✭✭
    Did this post once have code included?  Sounds like yes but it's vanished.
    Creating knowledge-driven design automation software, for molds, etc.
    www.virtualmold.com

  • Options
    billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    I don't think the code was uploaded.

    I have the steps in php & nodejs. There's plenty of python examples. Have you checked out the github repository for onshape?

    My code isn't commented and probably would do more harm than good if I posted it.

    oauth is a simple dance between your client, your server & onshape.

    Look at the github and if that doesn't work, then I'll compose a video showing how it's done. That might be best.



Sign In or Register to comment.