Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
yet another OAuth util
require 'rubygems'
require 'oauth'
require 'awesome_print'
require 'uri'
# Usage:
# 1) Get consumer key/secret from
# 2) Run ruby oauth_util.rb
# 3) Authorize as instructed
# 4) $$$
uri = URI.parse ARGV[0]
consumer =
:site => "#{uri.scheme}://#{}",
:request_token_path => "/oauth/request_token",
:access_token_path => "/oauth/access_token",
:authorize_path => "/oauth/authorize"
storage = './oauth_token'
if File.exists? storage
token, secret =',')
access_token = consumer, token, secret
request_token = consumer.get_request_token rescue \
abort("Request token fail! Typo in site name, key, or secret?")
puts "All right!", "1) Go here:", request_token.authorize_url, "2) Paste PIN here:"
code = $stdin.gets.chomp
access_token = request_token.get_access_token :oauth_token_verifier => code, 'w') {|f| f.write "#{access_token.token},#{access_token.secret}"}
# See oauth gem docs for access_token usage:
awesome_print access_token.get uri.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment