Project

micro_auth

0.0
No commit activity in last 3 years
No release in over 3 years
A super simple session-based authentication gem, for when you need to add basic admin capability to a single-user Rails app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.1
 Project Readme

Micro Auth

An absolutely tiny session-based authentication gem, for when you need to add basic admin capability to a single-user Rails app.

Need something more powerful? I recommend Sorcery for Authentication and CanCan for Authorization.

Setup

Micro Auth sets up a simple administrator login for your app. To set the username and password just define environment variables: LOGIN_NAME and PASSWORD.

If you don't provide these environment variables the login name will be example, and the password will be secret.

Usage

Micro Auth adds a few simple methods to your app:

authenticate # Use this in controllers as a before_filter to require login
admin? # Use this in controllers or views to see if the admin is logged in

Micro Auth also adds two self explanatory named routes, login and logout.

Tying it all together, anywhere in your app, you could do this:

- unless admin?
	= link_to 'Login', login_path
- if admin?
	= link_to 'Logout', logout_path

Custom login forms

Micro Auth provides a default login view for your convenience, however you can stick your own login form anywhere you want. Your form just needs to post :login and :pass to micro_auth_sessions_path to work. Here's the most basic example.

= form_tag micro_auth_sessions_path do
	= label_tag :login, "Login Name"
	= text_field_tag :login
	= label_tag :pass, "Password"
	= text_field_tag :pass
	= submit_tag

That's it!

This readme file takes up about as much text as the entire plugin, it's really simple. If you want to override the way it works... you might as well just implement it directly in your app.

Note: this works perfectly. However this is my first effort making a plugin that touches the controller layer, so I haven't figured out how to write automated tests for it yet. I'll get to that someday soon.

In the mean time feel free to fork the plugin, tweak it, and submit pull requests... perhaps if your pull requests include a test suite that will help me figure out how to do automated testing on a controller plugin.

Enjoy!