How to authenticate users using rubycas-server in rails?

669 views Asked by At

I'm using rubycas-server GEM as my CAS server. This CAS server is checking user credentials from a user table of a different database. These users are created using Devise gem. Devise saves every user's password in encrypted form in database table. So in the configuration file of this rubycas-server contains a authenticator section, It's code is given below:

authenticator:
 class: CASServer::Authenticators::SQL
 database:
   adapter: postgresql
   database: testdb
   username: postgres
   password: root
   host: localhost
   pool: 5
 user_table: users
 username_column: email
 password_column: encrypted_password
 encrypt_function: <encryption function>

As stated above in the last line of code that, encrypted_function contains the algorithm to check credentials. Some samples given gelow in the URL

https://code.google.com/p/rubycas-server/wiki/UsingTheSQLEncryptedAuthenticator

But I can't find what will be suitable for devise. Please help.

1

There are 1 answers

0
AudioBubble On BEST ANSWER

Finally I got solution for my question. Actually the encrypt_function: not needed in authenticator settings. As I'm using email and encrypted_password which is generated by Devise to check a user's credentials, the final authenticator is:

authenticator:
  class: CASServer::Authenticators::SQLBcrypt
  database:
   adapter: postgresql
   database: testdb
   username: postgres
   password: root
   host: localhost
   pool: 5
  user_table: users
  username_column: email
  password_column: encrypted_password

As Devise user BCrypt by default to encrypt the password, That's why I'm using CASServer::Authenticators::SQLBcrypt class. But rubycas-server gem don't set SQLBcrypt configurations by default. So go to lib/casserver/authenticators/authlogic_crypto_providers path and open brypt.rb file. In this file you can see these lines are commented, so un-comment them or if not present then add them

    acts_as_authentic do |c|
     c.crypto_provider = Authlogic::CryptoProviders::BCrypt
    end

Then run gem install bcrypt-ruby in your terminal or add this GEM to rubycas-server GEMFILE and restart the server. I think this should work.