micro_auth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +13 -0
- data/README.md +49 -0
- data/lib/micro_auth/application_controller.rb +23 -0
- data/lib/micro_auth/engine.rb +13 -0
- data/lib/micro_auth/version.rb +3 -0
- data/lib/micro_auth.rb +5 -0
- metadata +63 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012 Andrew Burleson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
4
|
+
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
5
|
+
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
6
|
+
Software is furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
11
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
12
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
13
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Micro Auth
|
2
|
+
|
3
|
+
An absolutely tiny session-based authentication gem, for when you need to add basic admin capability to a single-user Rails app.
|
4
|
+
|
5
|
+
Need something more powerful? I recommend Sorcery for Authentication and CanCan for Authorization.
|
6
|
+
|
7
|
+
## Setup
|
8
|
+
|
9
|
+
Micro Auth sets up a simple administrator login for your app. To set the username
|
10
|
+
and password just define environment variables: `LOGIN_NAME` and `PASSWORD`.
|
11
|
+
|
12
|
+
If you don't provide these environment variables the login name will be `example`, and the password will be `secret`.
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Micro Auth adds a few simple methods to your app:
|
17
|
+
|
18
|
+
authenticate # Use this in controllers as a before_filter to require login
|
19
|
+
admin? # Use this in controllers or views to see if the admin is logged in
|
20
|
+
|
21
|
+
Micro Auth also adds two self explanatory named routes, `login` and `logout`.
|
22
|
+
|
23
|
+
Tying it all together, anywhere in your app, you could do this:
|
24
|
+
|
25
|
+
- unless admin?
|
26
|
+
= link_to 'Login', login_path
|
27
|
+
- if admin?
|
28
|
+
= link_to 'Logout', logout_path
|
29
|
+
|
30
|
+
## Custom login forms
|
31
|
+
|
32
|
+
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.
|
33
|
+
|
34
|
+
= form_tag micro_auth_sessions_path do
|
35
|
+
= label_tag :login, "Login Name"
|
36
|
+
= text_field_tag :login
|
37
|
+
= label_tag :pass, "Password"
|
38
|
+
= text_field_tag :pass
|
39
|
+
= submit_tag
|
40
|
+
|
41
|
+
## That's it!
|
42
|
+
|
43
|
+
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.
|
44
|
+
|
45
|
+
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.
|
46
|
+
|
47
|
+
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.
|
48
|
+
|
49
|
+
Enjoy!
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MicroAuth
|
2
|
+
module ApplicationController
|
3
|
+
module ClassMethods
|
4
|
+
# Add class methods here in the future if needed.
|
5
|
+
end
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
|
9
|
+
# Simple filter method to verify user is admin in controllers.
|
10
|
+
def authenticate
|
11
|
+
unless admin?
|
12
|
+
session[:target] = request.path
|
13
|
+
redirect_to login_path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Simple method to see if user is authenticated as admin.
|
18
|
+
def admin?
|
19
|
+
session[:admin] == true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'micro_auth/application_controller'
|
2
|
+
|
3
|
+
module MicroAuth
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
initializer 'micro_auth.app_controller' do |app|
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
extend MicroAuth::ApplicationController::ClassMethods
|
8
|
+
include MicroAuth::ApplicationController::InstanceMethods
|
9
|
+
ActionController::Base.helper_method :admin?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/micro_auth.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: micro_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Burleson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &10437730 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *10437730
|
25
|
+
description: A super simple session-based authentication gem, for when you need to
|
26
|
+
add basic admin capability to a single-user Rails app.
|
27
|
+
email: andrew@eighty-b.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/micro_auth/application_controller.rb
|
33
|
+
- lib/micro_auth/engine.rb
|
34
|
+
- lib/micro_auth/version.rb
|
35
|
+
- lib/micro_auth.rb
|
36
|
+
- CHANGELOG
|
37
|
+
- README.md
|
38
|
+
- LICENSE
|
39
|
+
homepage: http://github.com/burlesona/micro_auth
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.10
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: An absolutely tiny authentication gem for single-admin rails apps.
|
63
|
+
test_files: []
|