Skip to content

Instantly share code, notes, and snippets.

@timothyklim
Created April 26, 2011 12:35
Show Gist options
  • Save timothyklim/942178 to your computer and use it in GitHub Desktop.
Save timothyklim/942178 to your computer and use it in GitHub Desktop.
test_oauth
require 'oauth'
URL = "http://localhost:9090/oauth/check"
CONSUMER_KEY = "c740398d919e199ff222be3f75b916e6" # App.first.consumer_key
CONSUMER_SECRET = "414e9edf0dd2f24fc78c6da47cbd2dd9" # App.first.consumer_secret
TOKEN_KEY = "4db6a2ce6f1dc173e9000002" # User.first.id
TOKEN_SECRET = "f8b3cb31ad6351af93e47f1a962f808a4e46038d" # User.first.tokens.first.secret
def prepare_access_token
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, { :site => URL })
token_hash = { :oauth_token => TOKEN_KEY, :oauth_token_secret => TOKEN_SECRET }
access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
return access_token
end
response = prepare_access_token.request(:get, URL)
puts response
# User.create! email: "[email protected]", password: "qwerty", username: "Yeah"
# User.first.apps.create! app_name: "Yeah"
# puts User.first.apps.consumer_key # => b79e2514f883c8d8d330fc483a7657c3
# curl -d "user[email][email protected]&user[password]=P244w0rd&consumer_key=b79e2514f883c8d8d330fc483a7657c3" http://localhost:9090/users/sign_in
# # => "token_key":"4db6a2ce6f1dc173e9000002","token_secret":"699f1206898c0e9c0b9c7f56016b2d28d9d9a1d9"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment