diff options
| author | mo khan <mo@mokhan.ca> | 2025-02-27 11:51:51 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-02-27 11:51:51 -0700 |
| commit | 2e4e414fc68752b2e2d1e3347c4fce54ddf5f26e (patch) | |
| tree | 2246325b6094c6068bc1fa2aa1a57282284dec4c | |
| parent | fc35bf1ab821445b71daf4fb25f303e29866d46b (diff) | |
Parse the saml response and display it on a webpage
| -rw-r--r-- | src/sp/main.rb | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/sp/main.rb b/src/sp/main.rb index 9ba9268a..68a0e3db 100644 --- a/src/sp/main.rb +++ b/src/sp/main.rb @@ -70,7 +70,7 @@ class ServiceProvider case path when "/assertions" # TODO:: Render the SAMLResponse from the IdP - return not_found + return assertions(Rack::Request.new(env)) else return not_found end @@ -85,15 +85,12 @@ class ServiceProvider end def post_to_idp(request) - entity_id = 'http://localhost:8282/metadata.xml' - idp = Saml::Kit.registry.metadata_for(entity_id) + idp = Saml::Kit.registry.metadata_for('http://localhost:8282/metadata.xml') relay_state = Base64.strict_encode64(JSON.generate(redirect_to: '/dashboard')) @saml_builder = nil uri, saml_params = idp.login_request_for(binding: :http_post, relay_state: relay_state) do |builder| @saml_builder = builder - # builder.issuer = params[:issuer] if params[:issuer].present? - # builder.assertion_consumer_service_url = callback_url end template = <<~ERB @@ -117,6 +114,27 @@ class ServiceProvider html = erb.result(binding) [200, { 'Content-Type' => "text/html" }, [html]] end + + def assertions(request) + sp = Saml::Kit.registry.metadata_for('http://localhost:8283/metadata.xml') + saml_binding = sp.assertion_consumer_service_for(binding: :http_post) + saml_response = saml_binding.deserialize(request.params) + raise saml_response.errors unless saml_response.valid? + + template = <<~ERB + <!doctype html> + <html> + <head><title></title></head> + <body style="background-color: pink;"> + <h2>Received SAML Response</h2> + <textarea readonly="readonly" disabled="disabled" cols=220 rows=40><%=- saml_response.to_xml(pretty: true) -%></textarea> + </body> + </html> + ERB + erb = ERB.new(template, nil, trim_mode: '-') + html = erb.result(binding) + [200, { 'Content-Type' => "text/html" }, [html]] + end end if __FILE__ == $0 |
