Skip to content

Instantly share code, notes, and snippets.

@volh
Last active September 24, 2015 23:58
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 volh/829606 to your computer and use it in GitHub Desktop.
Save volh/829606 to your computer and use it in GitHub Desktop.
Minimal Single Sign On using Sinatra
class SessionManager < Sinatra::Base
use Rack::Session::Memcache,
:key => 'customsessionkey',
:memcache_server => 'a.b.c.d:11211',
:cookie_only => false,
:secure => true,
:secret => 'secretpassphrase'
get '/cookies/set' do
# Newly set cookie points to the same session
session[:user].inspect
end
end
class SSOLoginApp < Sinatra::Base
use SessionManager
post '/login' do
session[:user] = User.authenticate(params.id)
MY_SSO_DOMAIN_LIST.map do |domain|
"<img src='https://#{domain}/cookies/set?customsessionkey=#{env['rack.session.options'][:id]}' style='display:none'></img>"
end.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment