Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 6f698319b3
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (60 sloc) 1.447 kb
module Hancock
module TestApp
module Helpers
def landing_page
"%h2 Hello #{session_user.inspect}!"
end
def unauthenticated
<<-HAML
%fieldset
%legend You need to log in, buddy.
%form{:action => '/sso/login', :method => 'POST'}
%label{:for => 'email'}
Email:
%input{:type => 'text', :name => 'email'}
%br
%label{:for => 'password'}
Password:
%input{:type => 'password', :name => 'password'}
%br
%input{:type => 'submit', :value => 'Login'}
or
%a{:href => '/sso/signup'} Signup
HAML
end
end
def self.registered(app)
app.helpers Helpers
app.get '/' do
ensure_authenticated
haml landing_page
end
end
def self.app
@app ||= Rack::Builder.new do
use Rack::Session::Cookie
run SsoServer
end
end
class SsoServer < ::Hancock::SSO::App
enable :raise_errors
disable :show_exceptions
error Hancock::SSO::Unauthenticated do
haml(unauthenticated)
end
error Hancock::SSO::Forbidden do
throw(:halt, [403, "Forbidden"])
end
error Hancock::SSO::BadRequest do
throw(:halt, [400, "Bad Request"])
end
error Hancock::SSO::LogMeOut do
redirect "/"
end
error Hancock::SSO::RouteMeHome do
redirect "/"
end
register(Hancock::TestApp)
end
end
end
Jump to Line
Something went wrong with that request. Please try again.