简体   繁体   中英

How do I use RelayState from SAML to specifiy landing page at the SP, using saml-omniauth and devise?

How do I use RelayState from SAML protocol to specify the landing page at SP in IdP initiated SSO ?

I have set an IdP initiated SSO process between IdP and SP. It works but it lands at root_path. I need this to land at RelayState URL.

I am using devise. Find below my controller:

def saml
    student = Student.where(email: request.env["omniauth.auth"]['uid'].to_s).first
    if student
      sign_in_and_redirect student, event: :authentication
    else
        flash[:error] = t 'flash_msg.access_1'
        redirect_to root_path
    end
  end

The answer is to substitute sign_in_and_redirect method by sign_in method only. Then redirect user to RelayState URL by doing redirect_to params[:RelayState] . Final saml method is:

  def saml
    student = Student.where(email: request.env["omniauth.auth"]['uid'].to_s).first
    if student
      sign_in student, event: :authentication
      redirect_to params[:RelayState]
    else
        flash[:error] = t 'flash_msg.access_1'
        redirect_to root_path
    end
  end

I hope it helps someone !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM