diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-18 16:35:05 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-18 16:35:05 -0600 |
| commit | 4e0b3504dddc7396cb1f24284bd5c39a1cea06c0 (patch) | |
| tree | ff9e8fdbe101590f3d7e6c1d09bc3f024f84cba5 /bin | |
| parent | 6b53e1e1d71f86b151f32e03026949b56fd26b43 (diff) | |
refactor: extract http helpers module
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/ui | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -107,7 +107,24 @@ module OAuth end end +module HTTPHelpers + def not_found + [404, { 'X-Backend-Server' => 'UI' }, []] + end + + def redirect_to(location) + if location.start_with?("http") + [302, { 'Location' => location }, []] + else + [302, { 'Location' => "http://ui.example.com:8080#{location}" }, []] + end + end + +end + class UI + include ::HTTPHelpers + attr_reader :oauth_client def initialize(oauth_client) @@ -150,7 +167,7 @@ class UI builder.organization_name = "Acme, Inc" builder.organization_url = "https://example.com" builder.build_service_provider do |x| - x.name_id_formats = [Saml::Kit::Namespaces::EMAIL_ADDRESS] + x.name_id_formats = [Saml::Kit::Namespaces::PERSISTENT] x.add_assertion_consumer_service("#{$scheme}://#{$host}/saml/assertions", binding: :http_post) end end @@ -158,19 +175,6 @@ class UI [200, { 'Content-Type' => "application/samlmetadata+xml" }, [xml]] end - - def not_found - [404, { 'X-Backend-Server' => 'UI' }, []] - end - - def redirect_to(location) - if location.start_with?("http") - [302, { 'Location' => location }, []] - else - [302, { 'Location' => "http://ui.example.com:8080#{location}" }, []] - end - end - def oauth_callback(request) response = oauth_client.exchange(grant_type: "authorization_code", code: request.params['code']) [response.code, response.header, [response.body]] @@ -216,14 +220,16 @@ class UI template = <<~ERB <!doctype html> <html> - <head><title></title></head> + <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, trim_mode: '-') + erb = ERB.new(template) html = erb.result(binding) [200, { 'Content-Type' => "text/html" }, [html]] end |
