We needed to create an integration from our installed application to a 3rd party web service. The integration requires an access token, which is retrieved from the web service during registration. Now, the web service uses OAuth 2 for authentication during the registration process.
This presented a challenge, as their OAuth implementation ultimately calls a redirect URL and includes the access token as a hash. How do we get the access token from web URL back into the installed application?
Our solution had to be dead simple, and work on a wide range of desktop operating systems. We considered a local web stack to accept the redirect URL, but that opens up a whole range of potential support issues with local firewalls and port conflicts.
My solution was to create a simple hosted web page that displayed the access token and made it easy for the end-user to copy it into the clipboard. Then, our installed application can retrieve the access token from the clipboard and store it to the database.
The workflow is as follows:
1. The installed application tells the user they need to register, and says “Click Next once you’ve registered”
2. The installation application opens an OAuth url provided by the web service.
2. The end-user gets a login page for the web service and provides their credentials.
3. The end-user is asked to confirm that they want to grant access to the web service.
4. At this point the web browser is redirected to a URL which includes the access token as a hash, like this
5. The redirect URL page parses out the access token and displays it on the page with instructions for the end-user. They first type Ctrl-C, which copies it into the clipboard, then click Done, which closes the browser window.
6. They click Next in the installed application which retrieves the access token from the clipboard and we’re done.
This process can be enhanced to store the access token on the web server along with a unique key. Then, the installed application can perform a GET to automatically retrieve it without the end-user needing to copy it.
Here’s the simple web page: