Sinatra Example

Marco Antonio edited this page Sep 29, 2018 · 12 revisions
    begin
      require 'sinatra'
      require 'omniauth'
      require 'openid/store/filesystem'
      require 'omniauth-twitter'

    rescue LoadError
      require 'rubygems'
      require 'sinatra'
      require 'omniauth'
      require 'openid/store/filesystem'
      require 'omniauth-twitter'
    end
    
    use Rack::Session::Cookie
    use OmniAuth::Builder do
      provider :open_id, OpenID::Store::Filesystem.new('/tmp')
      provider :twitter, 'consumerkey', 'consumersecret'
    end

    get '/' do
      <<-HTML
      <a href='/auth/twitter'>Sign in with Twitter</a>
      
      <form action='/auth/open_id' method='post'>
        <input type='text' name='identifier'/>
        <input type='submit' value='Sign in with OpenID'/>
      </form>
      HTML
    end
    
    post '/auth/:name/callback' do
      auth = request.env['omniauth.auth']
      # do whatever you want with the information!
    end
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.