Created
October 5, 2011 20:45
-
-
Save nsantorello/1265651 to your computer and use it in GitHub Desktop.
Bash script to get the OAuth2 token for a user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo '* Installing oauth2 Ruby gem' | |
gem install oauth2 | |
echo '* Done installing oauth2 gem' | |
echo '' | |
echo '* Enter your API ID:' | |
read apiid | |
echo '* Enter your API secret:' | |
read apisecret | |
echo '* Enter the OAuth2 site: (e.g. https://mysite.com):' | |
read site | |
authorize_url=`ruby -e "require 'rubygems'; require 'oauth2'; puts OAuth2::Client.new(\"$apiid\".strip, \"$apisecret\".strip, :site=>\"$site\".strip).auth_code.authorize_url(:redirect_uri => 'http://localhost/oauth2/callback')"` | |
echo '' | |
echo "* You are about to be redirected to $authorize_url" | |
echo '' | |
echo "***After authorizing, you'll be brought to a non-existent page. Copy the token in the URL you're redirected to (after 'code=') and paste below when prompted.***" | |
echo '' | |
echo '* Press ENTER to proceed!' | |
read | |
open $authorize_url | |
echo '* Enter your authorization code from the previous step:' | |
read auth_code | |
token=`ruby -e "require 'rubygems'; require 'oauth2'; puts OAuth2::Client.new(\"$apiid\".strip, \"$apisecret\".strip, :site=>\"$site\".strip).auth_code.get_token('$auth_code'.strip, :redirect_uri => 'http://localhost/oauth2/callback').token"` | |
echo '' | |
echo 'Your OAuth2 token is: ' | |
echo $token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment