diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-27 15:21:22 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-27 15:21:22 -0600 |
| commit | c55e51eeef2db8a3d4c7796b7d719b05dc46d2fa (patch) | |
| tree | 12f2e493bef320941d3e08cecca54266dcb77272 | |
| parent | dbb0cb79bd76458ac9e7084dd022d355cb7f8211 (diff) | |
refactor: extract method for UI landing page
| -rwxr-xr-x | bin/ui | 80 |
1 files changed, 42 insertions, 38 deletions
@@ -172,44 +172,7 @@ class UI when Rack::GET case request.path when "/index.html" - html = with_layout(binding) do - <<~ERB - <%- if current_user?(request) -%> - <nav> - <ul> - <li><a href="http://#{$idp_host}/">IdP</a></li> - <li><strong>UI</strong></li> - </ul> - <ul> - <li><a href="/index.html">Home</a></li> - <li><a href="/groups.html">Groups</a></li> - <li> - <form action="/logout" method="post"> - <input type="submit" value="Logout" /> - </form> - </li> - </ul> - </nav> - <h1>Access Token</h1> - <pre><%= request.session[:access_token] %></pre> - - <h1>ID Token</h1> - <pre><%= request.session[:id_token] %></pre> - <%- else -%> - <nav> - <ul> - <li><a href="http://#{$idp_host}/">IdP</a></li> - <li><strong>UI</strong></li> - </ul> - <ul> - <li><a href="/saml/new">SAML Login</a></li> - <li><a href="/oidc/new">OIDC Login</a></li> - </ul> - </nav> - <%- end -%> - ERB - end - return [200, { 'Content-Type' => "text/html" }, [html]] + return get_index(request) when "/groups.html" if current_user?(request) return get_groups(request) @@ -268,6 +231,47 @@ class UI [200, { 'Content-Type' => "application/samlmetadata+xml" }, [xml]] end + def get_index(request) + html = with_layout(binding) do + <<~ERB + <%- if current_user?(request) -%> + <nav> + <ul> + <li><a href="http://#{$idp_host}/">IdP</a></li> + <li><strong>UI</strong></li> + </ul> + <ul> + <li><a href="/index.html">Home</a></li> + <li><a href="/groups.html">Groups</a></li> + <li> + <form action="/logout" method="post"> + <input type="submit" value="Logout" /> + </form> + </li> + </ul> + </nav> + <h1>Access Token</h1> + <pre><%= request.session[:access_token] %></pre> + + <h1>ID Token</h1> + <pre><%= request.session[:id_token] %></pre> + <%- else -%> + <nav> + <ul> + <li><a href="http://#{$idp_host}/">IdP</a></li> + <li><strong>UI</strong></li> + </ul> + <ul> + <li><a href="/saml/new">SAML Login</a></li> + <li><a href="/oidc/new">OIDC Login</a></li> + </ul> + </nav> + <%- end -%> + ERB + end + [200, { "Content-Type" => "text/html" }, [html]] + end + def oauth_callback(request) response = oauth_client.exchange("authorization_code", code: request.params['code']) if response.code == "200" |
