Last active
August 29, 2015 13:59
-
-
Save masylum/10976663 to your computer and use it in GitHub Desktop.
Redbooth oauth example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './redbooth-oauth-example' | |
run RedboothOAuthExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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