diff options
Diffstat (limited to 'bin/sp')
| -rwxr-xr-x | bin/sp | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -59,15 +59,17 @@ class ServiceProvider case path when "/metadata.xml" return metadata + when "/openid/new" + return redirect_to("http://localhost:8282/oauth/authorize?client_id=service-provider&state=example&redirect_uri=http://localhost:8283/oauth/callback&response_type=code&response_mode=query&scope=openid") + when "/oauth/callback" + return oauth_callback(Rack::Request.new(env)) else - # TODO Generate a post to the IdP - return post_to_idp(Rack::Request.new(env)) + return saml_post_to_idp(Rack::Request.new(env)) end when 'POST' case path when "/assertions" - # TODO:: Render the SAMLResponse from the IdP - return assertions(Rack::Request.new(env)) + return saml_assertions(Rack::Request.new(env)) else return not_found end @@ -81,7 +83,16 @@ class ServiceProvider [404, {}, []] end - def post_to_idp(request) + def redirect_to(location) + [302, { 'Location' => location }, []] + end + + def oauth_callback(request) + # TODO:: Exchange grant (authorization_code) for an access token + [200, { "Content-Type" => "application/json" }, [JSON.pretty_generate(request.params)]] + end + + def saml_post_to_idp(request) idp = Saml::Kit.registry.metadata_for('http://localhost:8282/metadata.xml') relay_state = Base64.strict_encode64(JSON.generate(redirect_to: '/dashboard')) @@ -107,12 +118,11 @@ class ServiceProvider </body> </html> ERB - erb = ERB.new(template, trim_mode: '-') - html = erb.result(binding) + html = ERB.new(template, trim_mode: '-').result(binding) [200, { 'Content-Type' => "text/html" }, [html]] end - def assertions(request) + def saml_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) |
