Skip to content

Instantly share code, notes, and snippets.

@cyberfox
Created August 28, 2015 06:18
Show Gist options
  • Save cyberfox/44de7f5f70b5e8916425 to your computer and use it in GitHub Desktop.
Save cyberfox/44de7f5f70b5e8916425 to your computer and use it in GitHub Desktop.
Simple Salesforce & Twitter OAuth2 Sinatra client
require 'sinatra'
require 'omniauth-twitter'
require 'omniauth-salesforce'
configure do
enable :sessions
end
helpers do
def h(text)
Rack::Utils.escape_html(text)
end
end
use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_CONSUMER_KEY'], ENV['TWITTER_CONSUMER_SECRET']
provider :salesforce, ENV['SALESFORCE_CONSUMER_KEY'], ENV['SALESFORCE_CONSUMER_SECRET']
end
OmniAuth.config.full_host = "https://auth.vulpine.com"
get '/test' do
erb("<%= h 'Succ<ess>ful.'%>")
end
get '/login/twitter' do
redirect to('/auth/twitter')
end
get '/login' do
redirect to('/auth/salesforce')
end
get '/auth/:provider/callback' do
puts env['omniauth.auth'].inspect
session[:user] = env['omniauth.auth']['raw_info']
session[:uid] = env['omniauth.auth']['uid']
session[:logged_in] = true
erb <<-EOHTML
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Hello <%= h env['omniauth.auth']['info']['name'] %>!</h1>
<br/>
<%= h env['omniauth.auth'].inspect %>
<br/>
<br/>
From provider: #{env['omniauth.auth']['provider']} vs. #{params[:provider]}
</body>
</html>
EOHTML
end
get '/auth/failure' do
params[:message]
end
source 'https://www.rubygems.org'
gem 'sinatra'
gem 'omniauth-twitter'
gem 'omniauth-salesforce'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment