Skip to content

Instantly share code, notes, and snippets.

Forked from fairchild/Gemfile
Created October 16, 2012 22:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save syntacticsugar/3902574 to your computer and use it in GitHub Desktop.
An example sinatra omniauth client app
require "rubygems"
require 'example_omniauth_app'
run SinatraApp
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
use OmniAuth::Builder do
provider :github, 'ece9da5a3cff23b3475f','eb81c6098ba5d08e3c2dbd263bf11de5f3382d55'
provider :facebook, '290594154312564','a26bcf9d7e254db82566f31c9d72c94e'
provider :twitter, 'cO23zABqRXQpkmAXa8MRw', 'TwtroETQ6sEDWW8HEgt0CUWxTavwFcMgAwqHdb0k1M'
#provider :att, 'client_id', 'client_secret', :callback_url => (ENV['BASE_DOMAIN']
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>"
get '/auth/:provider/callback' do
erb "<h1>#{params[:provider]}</h1>
get '/auth/failure' do
erb "<h1>Authentication Failed:</h1><h3>message:<h3> <pre>#{params}</pre>"
get '/auth/:provider/deauthorized' do
erb "#{params[:provider]} has deauthorized this app."
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>"
get '/logout' do
session[:authenticated] = false
redirect '/'
end! if __FILE__ == $0
@@ layout
<link href='' rel='stylesheet' />
<div class='container'>
<div class='content'>
<%= yield %>
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment