rack-auth-simples 0.0.1 → 0.0.2
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 -0
- data/lib/rack/auth/simples/rules.rb +27 -7
- data/lib/rack/auth/simples.rb +1 -5
- data/lib/rack-auth-simples/version.rb +2 -2
- metadata +2 -1
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rack-auth-simples-0.0.1.gem
|
@@ -9,9 +9,19 @@ module Rack
|
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@ips = []
|
12
|
-
@triggers = []
|
12
|
+
@triggers = []
|
13
|
+
|
14
|
+
@opts = {
|
15
|
+
:secret => 'SET_VIA_CONFIG',
|
16
|
+
:return_url => '/',
|
17
|
+
:cookie_name => '_auth_allowed'
|
18
|
+
}
|
13
19
|
end
|
14
20
|
|
21
|
+
def set_options opts
|
22
|
+
@opts.merge! opts
|
23
|
+
end
|
24
|
+
|
15
25
|
def add_ip ip
|
16
26
|
@ips << ip
|
17
27
|
end
|
@@ -24,7 +34,9 @@ module Rack
|
|
24
34
|
@triggers << url
|
25
35
|
end
|
26
36
|
|
27
|
-
def
|
37
|
+
def parse env, app
|
38
|
+
|
39
|
+
fail = [403, {'Content-Type' => 'text/plain' }, ['Forbidden'] ]
|
28
40
|
|
29
41
|
if env['HTTP_X_FORWARDED_FOR']
|
30
42
|
ip = env['HTTP_X_FORWARDED_FOR'].split(',').pop
|
@@ -35,21 +47,29 @@ module Rack
|
|
35
47
|
|
36
48
|
if @ips.any?
|
37
49
|
addrs_list = IPAddrList.new(@ips)
|
38
|
-
return
|
50
|
+
return fail unless addrs_list.include? ip
|
39
51
|
end
|
40
52
|
|
41
53
|
if @triggers.any?
|
42
54
|
|
43
|
-
|
55
|
+
cookie = Rack::Request.new(env).cookies[@opts[:cookie_name]]
|
56
|
+
|
57
|
+
return app.call(env) if cookie == @opts[:secret]
|
58
|
+
|
59
|
+
if @triggers.include? env['PATH_INFO']
|
60
|
+
|
61
|
+
headers = {'Location' => @opts[:return_url]}
|
62
|
+
Rack::Utils.set_cookie_header!(headers, @opts[:cookie_name], {:value => @opts[:secret], :path => "/"})
|
63
|
+
return [302, headers, ['']]
|
44
64
|
|
45
|
-
|
65
|
+
end
|
46
66
|
|
47
|
-
|
67
|
+
return fail
|
48
68
|
|
49
69
|
end
|
50
70
|
|
51
71
|
# default to true
|
52
|
-
return
|
72
|
+
return app.call env
|
53
73
|
|
54
74
|
end
|
55
75
|
|
data/lib/rack/auth/simples.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-auth-simples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -34,6 +34,7 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
+
- .gitignore
|
37
38
|
- Gemfile
|
38
39
|
- lib/rack-auth-simples/version.rb
|
39
40
|
- lib/rack/auth/simples.rb
|