Adding login.gatech.edu support to a Ruby on Rails v2.x app
1. Add gem dependency to rubycas-client gem (http://code.google.com/p/rubycas-client/).
In config/environment.rb, inside Rails::Initializer block, add the following:
config.gem "rubycas-client", :lib => 'casclient'
2. From the command line, install the gem by running:
rake gems:install
3. Create a file config/initializers/cas.rb, containing:
# CAS configuration require 'casclient'require 'casclient/frameworks/rails/filter'CASClient::Frameworks::Rails::Filter.configure(:cas_base_url => "https://login.gatech.edu/cas/" )
See the rubycas-client documentation (http://rubycas-client.rubyforge.org/) for
more options for customizing the CAS client behavior.
4. In your ApplicationController class (app/controllers/application.rb), add
the following line:
before_filter CASClient::Frameworks::Rails::Filter
Now once you restart your server, your entire app will be CASified, and any action
will redirect to login.gatech.edu for authentication if the browser has not already
been authenticated. After login, the user will be redirected back to your app.
The GT Account username of the logged in user will be available to your code in the session:
session[:cas_user]
If you would like to only require login for specific controllers, you
can move the before_filter out of the ApplicationController, and into only
those controllers. See the rails documentation for information on restricting
filters to specific actions.