Skip to content

Instantly share code, notes, and snippets.

@sevenseacat
Created June 24, 2016 00:47
Show Gist options
  • Save sevenseacat/a978b04064aa4956df44bab0181cab8e to your computer and use it in GitHub Desktop.
Save sevenseacat/a978b04064aa4956df44bab0181cab8e to your computer and use it in GitHub Desktop.

Box 6.1. Roll your own authentication system

Virtually all web applications require a login and authentication system of some sort. As a result, most web frameworks have a plethora of options for implementing such systems, and Rails is no exception. Examples of authentication and authorization systems include Clearance, Authlogic, Devise, and CanCan (as well as non-Rails-specific solutions built on top of OpenID or OAuth). It’s reasonable to ask why we should reinvent the wheel. Why not just use an off-the-shelf solution instead of rolling our own?

For one, practical experience shows that authentication on most sites requires extensive customization, and modifying a third-party product is often more work than writing the system from scratch. In addition, off-the-shelf systems can be “black boxes”, with potentially mysterious innards; when you write your own system, you are far more likely to understand it. Moreover, recent additions to Rails (Section 6.3) make it easy to write a custom authentication system. Finally, if you do end up using a third-party system later on, you’ll be in a much better position to understand and modify it if you’ve first built one yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment