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.

Revisions

  1. cyberfox created this gist Aug 28, 2015.
    60 changes: 60 additions & 0 deletions oauth_sinatra_client.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    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
    5 changes: 5 additions & 0 deletions ​Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    source 'https://www.rubygems.org'

    gem 'sinatra'
    gem 'omniauth-twitter'
    gem 'omniauth-salesforce'