forked from enterprise-oss/sinatra-ruby-idp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
80 lines (61 loc) · 1.44 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require "sinatra/reloader"
require "sinatra/cookies"
require "zeitwerk"
require "figaro"
loader = Zeitwerk::Loader.new
loader.push_dir("lib")
loader.setup # ready!
class MockSamlIdpApp < Sinatra::Base
set :method_override, true
set :haml, escape_html: false, layout: :application
enable :raise_errors
enable :logging
disable :show_exceptions
include SamlIdp::Controller
@user_ids = Hash.new(SecureRandom.uuid)
helpers do
def user_ids
@user_ids ||= Hash.new(SecureRandom.uuid)
end
end
before do
cache_control :public, :must_revalidate, :max_age => 0
end
error 500 do
send_file('public/500.html')
end
error 404 do
send_file('public/404.html')
end
get "/healthcheck" do
"Yes I am alive"
end
get '/' do
haml :login
end
get '/saml-login' do
haml :login
end
post '/decode-saml-request' do
json = JSON.parse(request.body.read)
saml_request = json['SAMLRequest']
{decodedSamlRequest: decode_request(saml_request).raw_xml}.to_json
end
post '/saml-login' do
decode_request(params[:SAMLRequest])
@saml_response = encode_response(fake_user, signed_message: true)
haml :saml_post
end
get '/saml-login-authed' do
@saml_response = encode_response(fake_user)
haml :saml_post
end
private
def fake_user
email_address = params[:username]
OpenStruct.new({
email_address: email_address,
id: user_ids[email_address],
})
end
end