forked from sbower/samlsp-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
executable file
·50 lines (38 loc) · 1.22 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
require 'sinatra/base'
require 'onelogin/ruby-saml'
require 'json'
class App < Sinatra::Base
set :bind, "0.0.0.0"
configure do
set :cache_control, :no_store
set :static_cache_control, :no_store
end
get "/" do
"<p>The site is up!</p>"
end
get '/saml/authentication_request' do
request = OneLogin::RubySaml::Authrequest.new
redirect request.create(get_saml_settings)
end
post '/saml/consume' do
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse])
response.settings = get_saml_settings
if response.is_valid?
"Success! Hello #{response.attributes['urn:oid:2.5.4.42']}!"
else
'Error'
end
end
get '/saml/metadata' do
meta = OneLogin::RubySaml::Metadata.new
content_type 'text/xml'
meta.generate(get_saml_settings, true)
end
def get_saml_settings
idp_metadata_parser = OneLogin::RubySaml::IdpMetadataParser.new
settings = idp_metadata_parser.parse_remote("https://shibidp-test.cit.cornell.edu/idp/shibboleth")
settings.assertion_consumer_service_url = "https://shib.srb55.cs.cucloud.net/saml/consume"
settings.issuer = "https://shib.srb55.cs.cucloud.net/saml/metadata"
settings
end
end