Home arrow Tricks, Tips, and Help arrow Advanced Tips arrow Rails Auth with http and msql
Rails Auth with http and msql Print E-mail
So I am running a RHEL5 server and I have a few Ruby on Rails Apps that I want to protect with http auth in apache but be able to manage the users and passwords with mysql (and within rails). So I found the mod_auth_mysql

> yum install mod_auth_mysql


Then I added the module to http.conf at the end of the LoadModules

LoadModule mysql_auth_module modules/mod_auth_mysql.so

Following this I reloaded apache /etc/init.d/httpd reload

Next I need to make my model in rails, I go to my rails root

> script/generate model user name:string password:string group_id:integer

then rake db:migrate to update the mysql database.

Next I get my db username and password from config/database.yml and use that to setup my .htaccess file
>vim public/.htaccess
I add these lines to the htaccess file

####Rails mysql auth with http
AuthName "Please Login"
AuthType Basic
AuthMySQLHost localhost
AuthMYSQLEnable on
AuthMySQLDB DBNAME
AuthMySQLUserTable users
AuthMySQLUser MYSQLDbUSER
AuthMySQLPassword MYSQLDBPass
AuthMySQLNameField name
AuthMySQLPasswordField password
#AuthMySQLAuthoritative On
require valid-user

Then I open script/console, and I had to crypt the password
> script/console
u = User.new()
u.name=username
u.password = "pwd".crypt("pwd")

u.save

Since I am running rails through Apache/Mongrel I just go to my rails public directory
http://rails.jibwa.com
And I type in my user and pas and I'm in.

So now I need to setup rails for http auth

This tends to get more difficult because the way you configure for mongrel is different then the way it is supposed to be configured for apache/mongrel. I ended up with too many problems and just wrote my own flex frontend and a rails data model to handle it. If anyone is interested in how to do that let me know!
 
< Prev   Next >

Jibwa Work Samples

Under Construction

Jibwa.com is under construction. Watch out for broken links, missing pages, potholes and bulldozers. We apologize for the temporary inconvenience - Jibwa.com Staff

News and Updates

Boyd Energy Site

A energy engineer wanted a place to share his knowledge of energy conservation and other building type technologies. Using Joomla 1.5 we have a site u...
Read More ...

Restart Cable Modem and Router

If you have a modem (Cable, DSL, T1, Other), and a router you are probably familiar with the power cycle! The power cycle is three simple steps and ...
Read More ...

Lecture Audio Clip Player

Mark Pirtle Website Russell Public was interested in having Mark's audio samples playable for visitors of the website. In order to do this we had to ...
Read More ...

Plush Animation and demo shot

&amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;...
Read More ...