Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Examples of integrating with Shibboleth and CAS

Table of Contents

Authenticate against Shibboleth

There are probably many ways of doing this.

Data Curation Experts has a repeatable way for accomplishing it, documented here.

Authenticate against CAS

Again, there are probably several ways to do this. This method uses a gem called https://github.com/nbudin/devise_cas_authenticatable.

\uD83D\uDCD8 Instructions

...

Add the devise_cas_authenticatable gem

Add this line to your Gemfile:

Code Block
gem 'devise_cas_authenticatable'

Then run the command bundle install.

Modify the user model

Go to the file app/models/user.rb. Find this line:

Code Block
attr_accessible :email, :password, :password_confirmation #default line from the basic hyrax installation

Replace it with:

Code Block
attr_accessible :email

Next, find these lines:

Code Block
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

Replace them with:

Code Block
  devise :cas_authenticatable, 
     :recoverable, :rememberable, :trackable

Finally, add a function that takes extra attributes from your CAS server and maps them to fields in the Hyrax contributor profile. In this example, we will get the department name and email address.

Code Block
  def cas_extra_attributes=(extra_attributes)
    extra_attributes.each do |name, value|
      case name.to_sym
      when :department
        self.department = value
      when :email
        self.email = value
      end
    end
  end

Modify the devise initializer

Go to config/initializers/devise.rb and add the following lines, adding your specific CAS URL. There are https://github.com/nbudin/devise_cas_authenticatable#setup that you can add to this initializer.

Code Block
config.cas_base_url = '[YOUR CAS URL GOES HERE]'
config.cas_user_identifier = 'email'
config.cas_username_column = 'email'

Add a username field to your database

Create a migration like this:

Code Block
class AddUsernameToUsers < ActiveRecord::Migration[5.1]
  def change
    add_column :users, :username, :string
  end
end

Run rails db:migrate

...