background preloader

Helpful devise articles

Facebook Twitter

Gotealeaf. Devise is a popular authentication solution for Rails applications.

gotealeaf

It provides a full gamut of features, and can be configured to meet all, but the most unusual, requirements. In this tutorial, we are going to look at how Devise is implemented on a high level, go through configueration and common use patterns of the gem, how to set up authentication with Devise, and finally demostrate how to write tests with Devise. Devise and Warden The Devise gem is built on top of Warden. Warden is a Rack application, which means that it runs as a separate and standalone module, and is (nearly always) executed before the chief Rails application is invoked. Warden provides the cookie handling that verifies the identity of a logged in user via a (secure) session string, in which the id (primary key) of a particular user is somehow stored and disguised.

Warden knows nothing about the existence of your Rails app. Devise Authentication in Depth. This is the second article in the “Authentication with Rails” series.

Devise Authentication in Depth

We are going to discuss Devise, a popular, full-fledged authentication solution by Platformatec. In comparison to Sorcery (which I looked at last time), Devise is a more high-level solution that takes care of many different aspects for you. It presents controllers, views, mailers, and routes. While it’s simple to issue a couple of commands an have Devise up and running, it is highly customizable. Devise has very thorough documentation and a large community that produces a boatload of useful extensions. Devise comes with a handful of modules, allowing you to choose only the required ones.

How to Build Authentication in Rails. Authentication is the process of establishing, and subsequently confirming, a site user’s identity.

How to Build Authentication in Rails

It is how an app recognises, who you are. In this article, we’ll go through a few methods that you can add authenticate to your Rails application. We’ll start with the HTTP Basic Authentication, look at the most commonly used username and password based local authentication, and then some less known alternatives. 1. HTTP Basic Authentication In HTTP Basic Authentication a user’s credentials are stored in a HTTP header field, and are sent as a part of each (HTTP) request.

There are a few variations on this theme, notably the authenticate_with_http_basic method, which yields the given username and password to a block, which returns a true value if the supplied credentials are valid. However, there are a number of security vulnerabilities in using these methods, to say the very least. Some other disadvantages are: 2. Storing passwords Here’s an example: Let’s see the same code using bcrypt. Allow users to authenticate with username only using Devise, ActiveAdmin, Rails 4 and Ruby 2 - Alex Popov. Probably there are not many cases where one wouldn't wont their users to have email addresses.

Allow users to authenticate with username only using Devise, ActiveAdmin, Rails 4 and Ruby 2 - Alex Popov

Nevertheless, I had exactly this situation recently. It was quite a challenge (for me at least) to figure out all the things one needs to change in Devise, so as not to expect users to provide an email upon registration and sign-in and to work properly. Finally, I was able to set it to work properly and decided to save you the trouble, in case some of you have a similar setup. Scenario You are using ActiveAdmin (AA), Devise, Rails 4 and Ruby 2. Source You can view the source on Github. Conventions I refer to the files unser app/models/ as models and the files under app/admin/ as resources.

Episode 210 - Customizing Devise” (view original Railscast) Other translations: In the previous episode [watch, read] we showed how to set up devise for user authentication in a Rails application.

Episode 210 - Customizing Devise”

This time we’ll continue from where we left off and show you how to customize devise. We’ll be working with the same application we used last time so we already have some authentication in place, with pages for signing up, logging in and logging out of the application. Restricting Access. Authentication With Devise Using Username – Configuration « John Plummer . com. Devise is probably the most popular authentication gem for Rails apps but, in the current version (1.1.5), doesn’t fully support logging in with a username and password.

Authentication With Devise Using Username – Configuration « John Plummer . com

This Railscast walks through how to add a username to the model and use username as the key to log in with but 1.1.5 will still require email as the key to unlock an account, reset a password or resend confirmation instructions. Version 1.2rc adds the ability to use username as a key for unlocking and resetting and I have submitted a patch to use username as a key when resending confirmations which will hopefully make it into a 1.2.x release. I have included my fork in the Gemfile below and will re-edit this post as future versions of devise are released. My patch has now been included in 1.2rc so use the url in your gemfile. I’ll keep this terse and include my workflow. How To: Allow users to sign in using their username or email address · plataformatec/devise Wiki. Allow users to Sign In using their username or email address For this example, we will assume your model is called User.

How To: Allow users to sign in using their username or email address · plataformatec/devise Wiki

Create a username field in the users table Create a migration: rails generate migration add_username_to_users username:string:uniq Run the migration: rake db:migrate Strong parameters Modify application_controller.rb and add username, email, password, password confirmation and remember me to configure_permitted_parameters class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? See also "strong parameters" Create a login virtual attribute in the User model Add login as an attr_accessor: # Virtual attribute for authenticating by either username or email # This is in addition to a real persisted field like 'username' attr_accessor :login or, if you will use this variable somewhere else in the code: def login=(login) @login = login end def login @login || self.username || self.email end For ActiveRecord: Ruby on rails - Devise authenticating with username instead of email.

Rails 4 + Devise Login with email or username and strong parameters.