In a Ruby on Rails application, I implemented as authentication OmniAuth with multiple providers(facebook and twitter for now), and I followed the steps from this github page: Managing Multiple Providers. Everything worked fine, I have a User class, in which a user is able to have many Identity objects.
Now I want to add a login with username and password, using OmniAuth Identity. My plan is to use the same Identity table, making this gem to store the password_digest field into the existing oauth_token, username into uid and use 'omniauth' as provider.
I am having difficulties in implementing this, trying to use the same model both for the externals auth(like facebook) and for this user/password, and I am wondering:
Is this a recommended way to do this?
Am I reinventing the wheel and such thing already exists?
Should I use a new Model just for this type of login(OmniAuth Identity)?
At the moment, I have different problems, such as not being able to tell the Identity gem that provider should have only one value, or my SessionsController doesn't work now good when I register for the first time.
Related
I've been battling at how to accomplish this for a while and even started working on different solutions only to notice it's not very practical or could lead to problems.
Scenario: A user can create an Admin account and invite (mail invite) another user as a Client. I was thinking of using the devise_invitable gem to handle the invitation process. I'm not sure if I should have 2 models (Admin/Client).
Gems I've been considering:
devise
devise_invitable
cancancan
pundit
rollify
The thing is that whatever setup I use for authentication and authorization must comply with devise_invitable gem given that its a load of my mind to build that functionality myself.
Devise and Oauth 2.0. If you need an admin panel you can use rails_admin or there are a variety of admin gems as well, Or you can make your own.
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!
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.
I would appreciate any links or examples as I am new to this and do not know where to start from. My application has basic authentication, I need to add OAuth to enable SSO, automatic log in a third party application.
Modify my user model to store OAuth parameters, modify a controller with login/logout actions
Use OmniAuth
https://github.com/intridea/omniauth
Devise and OmniAuth:
Create the standard devise User model and migration.
Create the Auth Controller actions (as show in the code snippet below)
Create the AccessGrant model (and if required the Authentication model)
Register the client applications (key and secret) via rails console on User Manager.
Use the oauth gem
https://github.com/albertopq/oauth-activeresource
Thanks for any pointers!
Use 2nd variant. It will be easier than others and you won't have any problems with integration another gems.
We're building a Rails 3 web application that will need to authorize and authenticate regular users who visit the site. Those same users may also use third-party applications to access the site via our API.
What approaches can we use to effectively and cleanly provide access to clients as well as users? What strategies have you used in your own Rails applications that also have RESTful APIs?
Ideally, we're after a solution which:
plays well with Devise and CanCan (which we already use for authn/authz)
plays well with Mongoid
doesn't pollute our controllers
is relatively simple to install and configure, if it's a gem or plugin
is easily testable, if it's a general strategy; or is already tested, if it's a gem or plugin
Since you're already using Devise, take a look at the token_authenticatable strategy (Add it to your user model and make sure the devise init reflects whatever you call the token param).
You'll want to add: "before_save :ensure_authentication_token" to your user model as well (assuming you don't want it to be single use).
Just provide your user's with their tokens on say their profile page or wherever. Call it an API token if you like.
I have two applications that use same database. Let's call them Site and API. I'm using Restful Authentication for user management.
If I create a user from "Site" this user doesn't work when try to login from API and vise versa. I can see the records are being saved in the same table.
Am I missing something? It should work?
I'm using Rails 3.
In your initializers/site_keys.rb REST_AUTH_SITE_KEY should be the same in your both applications then authentication will work properly in your both applications.