Web redirection after OneLogin SAML authentication

Viewed 514

I'm using the OneLogin Ruby-SAML gem, which we've been using to successfully authenticate our users for a while now. However, one small niggle remains - how to redirect a Ruby on Rails app to display the originally requested page, rather than just the default login screen after (re-)authenticating a session.

Traditionally this was done with a 'redirect_to' query parameter, e.g. https://fqdn/login.html?redirect_to="<originally_requested_page>"

How would I achieve this with a SAML OneLogin auth handshake in the way though?

1 Answers

In Addition to the SAMLRequest sent to the IdP SSO URL, you need to send a RelayState parameter with the originally_requested_page.

The IdP will maintain such RelayState parameter and return it back in addition to the SAMLResponse so on the SP Assertion Consumer Service endpoint you will be able to retrieve such RelayState.

Alternatively, instead of sending the URL, you can save such value in a cookie/session and send its key, so later, on the ACS endpoint you can recover such cookie/session and get the original stored URL value.

request = OneLogin::RubySaml::Authrequest.new
redirect_to(request.create(settings, :RelayState => original_url))
Related