= case request.scheme when "http" request.port == 80 ? "" : ":#{request.port}" when "https" request.port == 443 ? "" : ":#{request.port}" end "#{request.scheme}://#{request.host}#{port_part}#{suffix}" end end Thursday, May 14, 2009
File.expand_path(File.dirname(__FILE__)+'/views/sessions') File.read("#{template}/#{file}.haml") end module Helpers def session_user session['user_id'].nil? ? nil : ::Hancock::User.get(session['user_id']) end end def self.registered(app) app.helpers(Sinatra::Hancock::Sessions::Helpers) app.template(:unauthenticated) { sessions_template ('unauthenticated') } app.get '/sso/login' do ensure_authenticated end app.post '/sso/login' do @user = ::Hancock::User.authenticate(params['email'], params['password']) if @user session['user_id'] = @user.id end ensure_authenticated redirect session['return_to'] || '/' end app.get '/sso/logout' do session.clear redirect '/' end end end end end Thursday, May 14, 2009
Sinatra::Default enable :sessions set :sreg_params, [:email, :first_name, :last_name, :internal] set :provider_name, 'Hancock SSO Provider!' set :do_not_reply, nil register Sinatra::Hancock::Defaults register Sinatra::Hancock::Sessions register Sinatra::Hancock::Users register Sinatra::Hancock::OpenIDServer end end OMG LOOK WHAT I MADE! you can share it with your buddies Thursday, May 14, 2009
use Rack::Static, :urls => ["/css", "/img", "/js"], :root => "public" map "/gateway/" do use EySso run Gateway::App end map "/migration/" do use Rack::ShowExceptions if ENV["RACK_ENV"] == "production" use EySso do |sso| sso.only_staff! end end run Migration::App end map "/" do app = lambda do |env| [404, {"Content-Type" => "text/plain", "Content-Length" => "9"}, ["Not found"]] end run app end Thursday, May 14, 2009
use Rack::Static, :urls => ["/css", "/img", "/js"], :root => "public" map "/gateway/" do use EySso run Gateway::App end map "/migration/" do use Rack::ShowExceptions if ENV["RACK_ENV"] == "production" use EySso do |sso| sso.only_staff! end end run Migration::App end map "/" do app = lambda do |env| [404, {"Content-Type" => "text/plain", "Content-Length" => "9"}, ["Not found"]] end run app end Thursday, May 14, 2009
MyApp.new end def test_redirect_logged_in_users_to_dashboard authorize "bryan", "secret" get "/" follow_redirect! assert_equal "http://example.org/redirected", last_request.url assert last_response.ok? end end Thursday, May 14, 2009