Sahil Sahil - 1 year ago 78
Ruby Question

How to send the authenticated response while authenticating a user via SAML in Rails?

I have been trying to implement SAML in my application, wherein I want to authenticate the user and create the SAML Token(response) and redirect the user to the other website wherein session gets created.
Till now I have been able to get info on init method and consume method, which will be implemented by the other website.

def init
request =

def consume
response =[:SAMLResponse])
response.settings = saml_settings

if response.is_valid? && user = current_account.users.find_by_email(response.name_id)

Following this Source.

I want to create the method which comes in between init and consume.


Like I have this one which is I guess is following SAML 1.1, I wanted to know how can I generate a SAML 2.0 request using the get_settings method in Rails.

def SSOAccount.get_settings
settings =
settings.issuer = ""
settings.idp_sso_target_url =""
settings.idp_cert_fingerprint ="########"
settings.relying_party_identifier = "knsdfnsdf"
settings.assertion_consumer_service_url = ""
settings.idp_confirmation_method = "urn:oasis:names:tc:SAML:1.0:cm:bearer"
settings.asserting_party_id = "23424dfsdf"
settings.referer_url = ""
settings.groups = ["USER"]

Answer Source

You can post the data, but do it in a way that resembles a redirect. The problem with a redirect being that the data is usually larger than can be accommodated in a browser acceptable url.

You need to do it this way so that the post comes from the user's browser rather than your server. That is, the post needs to take the user's browser session with it, so that the associated cookies and session data are submitted with the SAML token.

One solution is to use a self submitting form as shown within saml_tools_demo's indentifies#create view.

Have a look at the matching controller action to see how the data are constructed.