Skip to content

Instantly share code, notes, and snippets.

@gorenje
Forked from fairchild/Gemfile
Created June 8, 2012 11:05

Revisions

  1. Gerrit Riessen revised this gist Jun 8, 2012. 2 changed files with 3 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@ gem 'json'
    gem 'omniauth'
    gem 'omniauth-oauth2'
    gem 'omniauth-github'
    gem 'omniauth-facebook'
    gem 'omniauth-twitter'
    # gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)

    gem 'thin'
    2 changes: 1 addition & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,4 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
    require "rubygems"
    require 'example_omniauth_app'

    run SinatraApp
    SinatraApp.run!
  2. @fairchild fairchild revised this gist Jan 5, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion example_omniauth_app.rb
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,8 @@ class SinatraApp < Sinatra::Base
    provider :github, 'ece9da5a3cff23b3475f','eb81c6098ba5d08e3c2dbd263bf11de5f3382d55'
    provider :facebook, '290594154312564','a26bcf9d7e254db82566f31c9d72c94e'
    provider :twitter, 'cO23zABqRXQpkmAXa8MRw', 'TwtroETQ6sEDWW8HEgt0CUWxTavwFcMgAwqHdb0k1M'
    #TODO provider :att, '', ''
    #provider :att, 'client_id', 'client_secret', :callback_url => (ENV['BASE_DOMAIN']

    end

    get '/' do
  3. @fairchild fairchild revised this gist Dec 7, 2011. 2 changed files with 18 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    source :rubygems

    gem 'sinatra'
    gem 'json'
    gem 'omniauth'
    gem 'omniauth-oauth2'
    gem 'omniauth-github'
    # gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)

    gem 'thin'
    group :development do
    gem 'shotgun'
    end
    5 changes: 5 additions & 0 deletions config.ru
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    $LOAD_PATH.unshift(File.dirname(__FILE__))
    require "rubygems"
    require 'example_omniauth_app'

    run SinatraApp
  4. @fairchild fairchild created this gist Dec 7, 2011.
    72 changes: 72 additions & 0 deletions example_omniauth_app.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    require 'rubygems'
    require 'sinatra'
    require 'json'
    require 'omniauth'
    require 'omniauth-github'
    require 'omniauth-facebook'
    require 'omniauth-twitter'
    #TODO require 'omniauth-att'

    class SinatraApp < Sinatra::Base
    configure do
    set :sessions, true
    set :inline_templates, true
    end
    use OmniAuth::Builder do
    provider :github, 'ece9da5a3cff23b3475f','eb81c6098ba5d08e3c2dbd263bf11de5f3382d55'
    provider :facebook, '290594154312564','a26bcf9d7e254db82566f31c9d72c94e'
    provider :twitter, 'cO23zABqRXQpkmAXa8MRw', 'TwtroETQ6sEDWW8HEgt0CUWxTavwFcMgAwqHdb0k1M'
    #TODO provider :att, '', ''
    end

    get '/' do
    erb "
    <a href='http://localhost:4567/auth/github'>Login with Github</a><br>
    <a href='http://localhost:4567/auth/facebook'>Login with facebook</a><br>
    <a href='http://localhost:4567/auth/twitter'>Login with twitter</a><br>
    <a href='http://localhost:4567/auth/att-foundry'>Login with att-foundry</a>"
    end

    get '/auth/:provider/callback' do
    erb "<h1>#{params[:provider]}</h1>
    <pre>#{JSON.pretty_generate(request.env['omniauth.auth'])}</pre>"
    end

    get '/auth/failure' do
    erb "<h1>Authentication Failed:</h1><h3>message:<h3> <pre>#{params}</pre>"
    end

    get '/auth/:provider/deauthorized' do
    erb "#{params[:provider]} has deauthorized this app."
    end

    get '/protected' do
    throw(:halt, [401, "Not authorized\n"]) unless session[:authenticated]
    erb "<pre>#{request.env['omniauth.auth'].to_json}</pre><hr>
    <a href='/logout'>Logout</a>"
    end

    get '/logout' do
    session[:authenticated] = false
    redirect '/'
    end

    end

    SinatraApp.run! if __FILE__ == $0

    __END__

    @@ layout
    <html>
    <head>
    <link href='http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css' rel='stylesheet' />
    </head>
    <body>
    <div class='container'>
    <div class='content'>
    <%= yield %>
    </div>
    </div>
    </body>
    </html>