rack-auth-simples 0.0.6 → 0.0.7
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/lib/rack/auth/simples/rules.rb +37 -5
- data/lib/rack-auth-simples/version.rb +1 -1
- metadata +2 -2
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'ipaddr'
|
2
2
|
require 'ipaddr_list'
|
3
|
+
|
4
|
+
require 'digest/md5'
|
5
|
+
|
3
6
|
module Rack
|
4
7
|
module Auth
|
5
8
|
|
@@ -18,7 +21,8 @@ module Rack
|
|
18
21
|
:return_url => '/',
|
19
22
|
:cookie_name => '_auth_allowed',
|
20
23
|
:fail => :forbidden,
|
21
|
-
:code_param => 'code'
|
24
|
+
:code_param => 'code',
|
25
|
+
:days => 14
|
22
26
|
}
|
23
27
|
end
|
24
28
|
|
@@ -75,7 +79,7 @@ module Rack
|
|
75
79
|
end
|
76
80
|
|
77
81
|
|
78
|
-
return app.call
|
82
|
+
return update_cookie(app.call env) if check_cookie(env)
|
79
83
|
|
80
84
|
|
81
85
|
if @triggers.any?
|
@@ -113,16 +117,44 @@ module Rack
|
|
113
117
|
|
114
118
|
private
|
115
119
|
|
116
|
-
def
|
117
|
-
Rack::Request.new(env).cookies[@opts[:cookie_name]]
|
120
|
+
def check_cookie env
|
121
|
+
value = Rack::Request.new(env).cookies[@opts[:cookie_name]]
|
122
|
+
|
123
|
+
if value.nil?
|
124
|
+
return false
|
125
|
+
else
|
126
|
+
time, hash = value.split('.')
|
127
|
+
expiry = time.to_i
|
128
|
+
return ( (expiry > Time.now.to_i) && (hash == cookie_hash(expiry)) )
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
def cookie_hash time = Time.now.to_i
|
134
|
+
::Digest::MD5.hexdigest "#{time.to_s}---#{@opts[:secret]}"
|
135
|
+
end
|
136
|
+
|
137
|
+
def cookie
|
138
|
+
expires = (Time.now + @opts[:days] * 86400)
|
139
|
+
{
|
140
|
+
:value => "#{expires.to_i.to_s}.#{cookie_hash expires.to_i}",
|
141
|
+
:path => "/",
|
142
|
+
:expires => expires
|
143
|
+
}
|
118
144
|
end
|
119
145
|
|
120
146
|
def set_cookie url = nil
|
121
147
|
headers = {'Location' => ( url || @opts[:return_url] ) }
|
122
|
-
Rack::Utils.set_cookie_header!(headers, @opts[:cookie_name],
|
148
|
+
Rack::Utils.set_cookie_header!(headers, @opts[:cookie_name], cookie)
|
123
149
|
return [302, headers, ['']]
|
124
150
|
end
|
125
151
|
|
152
|
+
def update_cookie response
|
153
|
+
status, headers, body = response
|
154
|
+
Rack::Utils.set_cookie_header!(headers, @opts[:cookie_name], cookie)
|
155
|
+
return [status, headers, body]
|
156
|
+
end
|
157
|
+
|
126
158
|
|
127
159
|
end
|
128
160
|
|
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.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ipaddr_list
|