Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
7kai Tasks OAuth sample for sinatra
# -rubygems を指定しなくても起動する様に
require 'rubygems' unless defined? ::Gem
require 'sinatra' # gem install sinatra
# require "sinatra/reloader" if development? # gem install sinatra-contrib
require 'erubis'
# require 'mysql2-cs-bind' # gem install mysql2-cs-bind
require 'rack/csrf' # gem install rack_csrf (CSRF対策)
require 'oauth' # gem install oauth
require 'json'
set :erb, :escape_html => true
configure do
use Rack::Session::Cookie, :secret => Digest::SHA1.hexdigest(rand.to_s)
use Rack::Csrf, :raise => true
callback_url = ''
consumer =
:site => '')
get '/' do
request_token = consumer.get_request_token(:oauth_callback => callback_url)
session[:request_token] = request_token
redirect request_token.authorize_url
get '/callback' do
request_token = session[:request_token]
access_token = request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
response = access_token.get('/api/1/account/me')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.