dlindahl / omniauth-cas

A CAS OmniAuth Strategy
MIT License
88 stars 79 forks source link

Add documentation for redirecting to the CAS login pages #8

Closed joevandyk closed 10 years ago

joevandyk commented 11 years ago

I'm not sure how to redirect the user to the CAS login/logoff pages. I know I can make the URL by hand, but I thought there'd be a better way? Is there a method for returning the CAS server's login and logoff URLs?

dlindahl commented 11 years ago

When the strategy fails, OmniAuth should handle the redirect itself. It will 302 the user to the URL defined in the login_url configuration option

Is that what you were looking for?

joevandyk commented 11 years ago

I might sometimes need to redirect people there outside of omniauth.

dlindahl commented 11 years ago

Unfortunately, I don't think that the OmniAuth API exposes a strategy's configuration options. I would suggest storing the login_url in a different location and use that variable when configuring OmniAuth::CAS.

In Rails, you should be able to do something like this:

# config/routes.rb
match 'users/sign_in' => 'users#sign_in', as: :sign_in

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :cas, host: 'cas.yourdomain.com', login_url: sign_in_path
end

Which would allow you to do this elsewhere:

<% link_to 'Sign In', sign_in_path %>