I’m trying to set up a 3-legged Oauth with Twitter so users can store credentials in my app. The issue I’m having is with the callback URL. Anvil uses the # to specify parameters, but Twitter returns a URL with query parameters.
I’m trying to get two query parameters from the URL Twitter is passing back. The user is directed to Twitter to login and give permissions, then sent back to my app with some oauth credentials in the URL. I’m using a Startup form to do the URL checks before routing the user to the appropriate form.
I’ve tried a few different things and seem to be hitting a wall:
Method 1: Use root domain as callback URL
Specify the root URL as the callback and capture query parameters with get_url_hash
. Unfortunately, the get_url_hash
method only grabs things after the #, which standard URL query parameters don’t have. So this doesn’t work.
Method 2: Manually add in Anvil style hash
I thought I would try to hack my way into this by adding an Anvil style hash to my callback. Something like:
https://anvilurl.anvil.app/#?source=twittercallback
Unfortunately, Twitter grabs the hash and throws it to the end (which is how hashes work in URLs right?) returning this:
https://anvilurl.anvil.app/?oauth_token=1234556&oauth_verifier=1234566#?source=twittercallback
So this doesn’t work.
Method 3: Add hash to callback
Really same as method 1, but I added a hash at the end of the callback to see what would happen.
https://anvilurl.anvil.app/#
And again it just moves the hash to the end.
API, you are my only hope…or maybe JS?
So what I’m thinking is that my callback will have to be an API call, as those support query strings. But I wouldn’t be able to redirect a user to a form via an API route right?
The other way is to open a popup and have the user copy/paste an auth code from Twitter. But this is really not ideal.