Skip to content

Instantly share code, notes, and snippets.

@masylum
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masylum/10976663 to your computer and use it in GitHub Desktop.
Save masylum/10976663 to your computer and use it in GitHub Desktop.
Redbooth oauth example
require './redbooth-oauth-example'
run RedboothOAuthExample
source "https://rubygems.org"
gem "thin", "~> 1.6.1"
gem "sinatra", "~> 1.4.4"
gem "json", "~> 1.8.1"
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-redbooth'
require 'sinatra/base'
require 'json'
require 'omniauth'
require 'omniauth-redbooth' # https://github.com/teambox/omniauth-redbooth
class RedboothOAuthExample < Sinatra::Base
configure do
set :sessions, true
set :inline_templates, true
end
use OmniAuth::Builder do
provider :redbooth, ENV['REDBOOTH_APP_ID'], ENV['REDBOOTH_APP_SECRET']
end
get '/' do
erb "<a href='/auth/redbooth'>Sign in with Redbooth</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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment