Last active
September 24, 2015 23:58
-
-
Save volh/829606 to your computer and use it in GitHub Desktop.
Minimal Single Sign On using Sinatra
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
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