I have a PostgreSQL database that I access from various locations, and would like to add an interface with Ruby on Rails 3. For authentication I need to login users with the same credentials used to create them directly in the database; is there a way to make Rails connect to the database each time with different username/password, based on the current user? Thanks for any hints!
-
Why would you want to do this?ybakos– ybakos2012-04-01 22:43:23 +00:00Commented Apr 1, 2012 at 22:43
-
1@ybakos to have consistency across the system and because inside the database there is a complex setup of triggers/functions that rely on users roles and permissionsworkingkills– workingkills2012-04-01 22:49:01 +00:00Commented Apr 1, 2012 at 22:49
Add a comment
|
1 Answer
Yes. Use a custom authentication on devise that makes a query to the underlying postgresql database.
See:
Custom authentication strategy for devise
I would certainly add some kind of filter to reduce the list of users that can authenticate this way.
2 Comments
workingkills
That looks like the way to do it! I'll check it out as soon as possible :)
mu is too short
But how does any of this change which (PostgreSQL) user is used to establish the connection to the database? Sure, you can authenticate the users using any mechanism you like but that doesn't alter the user/role attached to the database connection/session.