Ok, so that title should really read “Why and How…” since I’m starting with “Why”, but I don’t look backwards and neither should you. You’re an engineer and you have code to write and I have a blog to write. So off we go….
Some API providers only allow you to use a single callback URL when using an OAuth flow. Why? I haven’t the foggiest of ideas. That’s the route they decided to go, so Cloud Elements implemented a way for you to use a single callback to service multiple environments. Let’s say you have a single app for a Box integration your building. With that single app, you want to be able to hit both your testing and production environments. Well, out of the box (See what I did there) the provider does not allow that. So you can either spin up two apps, have environment variables in your code, and make a lot more work for yourself (Who has the time?). OR you can have one app with a proxy URL as the OAuth callback which has the ability to hit either environment. Your call, I’ll wait while you decide….
I like you. You’re still reading so I have to assume you want efficiency, not duplication. Smart.
If you still want to/are being forced by your API provider into using an OAuth Proxy URL, please follow along and I'll show you how to set this up. If you read through everything, there is also a fun video at the end. Less birthday-party-fun and more... "OOOOO now I see what he means" kind-of-fun.
- Choose your provider (for this example we are using Box)
- Get basic info for your app like API key and secret. Don’t fill in the redirect URL yet, we'll get to that in a bit.
- Log into your Cloud Elements account: https://my-staging.cloudelements.io
- In the lower left corner, click on the smiley face.
- Take note of your Organization and User secrets, we will need these later.
- Click on OAuth Proxy
- Click on "Create New OAuth Proxy" and fill in name with something descriptive and click "Create". Don’t worry about the API key and secret sections.
- You should now have a unique URL generated by Cloud elements. Paste this in the Redirect URL in the provider's website (See I told you we'd deal with the Redirect URL later)
- Now for the cURL GET command:
- The above should either give you a code or have you run through the OAuth flow which will render a code to you. Regardless, grab that code.
- Now we are going to create an instance by POSTing this:
- With any luck you should get back a 200 response code and a brand-new instance of <insert Element name here>!
Way to go!
As promised here is the video.
P.S. The "configuration" JSON object for the POST may have to be slightly modified depending on the Element you are using. Refer to the authentication tab for the given Element here.