rack-auth-simples 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/lib/rack/auth/simples/rules.rb +13 -2
- data/lib/rack-auth-simples/version.rb +1 -1
- metadata +1 -1
data/.gitignore
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
*.gem
|
|
@@ -10,11 +10,13 @@ module Rack
|
|
|
10
10
|
def initialize
|
|
11
11
|
@ips = []
|
|
12
12
|
@triggers = []
|
|
13
|
+
@exceptions = []
|
|
13
14
|
|
|
14
15
|
@opts = {
|
|
15
16
|
:secret => 'SET_VIA_CONFIG',
|
|
16
17
|
:return_url => '/',
|
|
17
|
-
:cookie_name => '_auth_allowed'
|
|
18
|
+
:cookie_name => '_auth_allowed',
|
|
19
|
+
:fail => :forbidden
|
|
18
20
|
}
|
|
19
21
|
end
|
|
20
22
|
|
|
@@ -26,6 +28,10 @@ module Rack
|
|
|
26
28
|
@ips << ip
|
|
27
29
|
end
|
|
28
30
|
|
|
31
|
+
def add_exception url
|
|
32
|
+
@exceptions << url
|
|
33
|
+
end
|
|
34
|
+
|
|
29
35
|
def allow_local
|
|
30
36
|
@ips << '127.0.0.1'
|
|
31
37
|
end
|
|
@@ -36,7 +42,11 @@ module Rack
|
|
|
36
42
|
|
|
37
43
|
def parse env, app
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
if @opts[:fail] == :forbidden
|
|
46
|
+
fail = [403, {'Content-Type' => 'text/plain' }, ['Forbidden'] ]
|
|
47
|
+
else
|
|
48
|
+
fail = [302, {'Location' => @opts[:fail] }, [] ]
|
|
49
|
+
end
|
|
40
50
|
|
|
41
51
|
if env['HTTP_X_FORWARDED_FOR']
|
|
42
52
|
ip = env['HTTP_X_FORWARDED_FOR'].split(',').pop
|
|
@@ -44,6 +54,7 @@ module Rack
|
|
|
44
54
|
ip = env["REMOTE_ADDR"]
|
|
45
55
|
end
|
|
46
56
|
|
|
57
|
+
return app.call(env) if @exceptions.include? env['PATH_INFO']
|
|
47
58
|
|
|
48
59
|
if @ips.any?
|
|
49
60
|
addrs_list = IPAddrList.new(@ips)
|