Skip to content

Instantly share code, notes, and snippets.

@reagent
Created November 7, 2010 02:26
Show Gist options
  • Save reagent/665914 to your computer and use it in GitHub Desktop.
Save reagent/665914 to your computer and use it in GitHub Desktop.
A simple Sinatra app to test the OAuth callback functionality in Etsy. To use: 1. Install dependencies 2. Supply a valid api key & secret 3. Run `ruby etsy_verification_app.rb` 4. Point a browser to http://localhost:4567/
require 'rubygems'
require 'sinatra'
require 'etsy'
enable :sessions
Etsy.access_mode = :read_write
Etsy.api_key = "key"
Etsy.api_secret = "secret"
Etsy.callback_url = "http://localhost:4567/verify"
get '/' do
%{
<form action="/authorize" method="post">
<button type="submit">Authorize Me!</button>
</form>
}
end
post '/authorize' do
request_token = Etsy.request_token
session[:request_token] = request_token.token
session[:request_secret] = request_token.secret
redirect Etsy.verification_url
end
get '/verify' do
token = Etsy.access_token(session[:request_token], session[:request_secret], params[:oauth_verifier])
session[:request_token] = nil
session[:request_secret] = nil
session[:access_token] = token.token
session[:access_secret] = token.secret
%{<p>You have been verified. Visit <a href="/me">your profile page</a></p>}
end
get '/me' do
user = Etsy.myself(session[:access_token], session[:access_secret])
%{<p>You are logged in as #{user.username}</p>}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment