demopass 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/Gemfile.lock +1 -1
- data/lib/demopass/app.rb +17 -4
- data/lib/demopass/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db808df5d6e5cd7a3afda85d10590eaada99da80d94fc2b7a01ef49f32861f21
|
4
|
+
data.tar.gz: 3598bd131b0d20e09c5c2dfa584654ba045754b7461f3d069a8bfc9baf74a8fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe48a975bcde99459f6c2696e0d93f061ca8c91089956b1b7ff3db3cac1c6385042ff6ecc6ce942528654b0bcd6167d305475a8ec447c03d7130ae3a73166718
|
7
|
+
data.tar.gz: 85b8c8cc117e7b2c4737cc70c6b6fa1757ea9c0dc3b3132300680e214bd3d98a3363c4483ecd438b71655768ff663a3c9cc040f544738fa12f3e680d1747062a
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/demopass/app.rb
CHANGED
@@ -5,22 +5,23 @@ class Demopass::App
|
|
5
5
|
PASSWORD_KEY = "password".freeze
|
6
6
|
TOKEN_KEY = "demopass_token".freeze
|
7
7
|
|
8
|
-
def initialize(downstream)
|
8
|
+
def initialize(downstream, except: nil)
|
9
9
|
@downstream = downstream
|
10
|
+
@except = except
|
10
11
|
@response = Rack::Response.new
|
11
12
|
|
12
13
|
@hmac_key = ENV["DEMOPASS_SECRET"]
|
13
14
|
@password = ENV["DEMOPASS_PASSWORD"]
|
14
15
|
|
15
|
-
raise Demopass::Error, "Please configure DEMOPASS_SECRET and DEMOPASS_PASSWORD" unless @hmac_key && @password
|
16
|
-
|
17
16
|
@digest = OpenSSL::Digest.new("SHA256")
|
18
17
|
@valid_hmac = hmac_for(@password)
|
18
|
+
|
19
|
+
validate_arguments
|
19
20
|
end
|
20
21
|
|
21
22
|
def call(env)
|
22
23
|
request = Rack::Request.new(env)
|
23
|
-
return @downstream.call(env) if token_valid?(request)
|
24
|
+
return @downstream.call(env) if path_excluded?(request) || token_valid?(request)
|
24
25
|
|
25
26
|
if (password = extract_password(request))
|
26
27
|
assign_token_and_redirect(password)
|
@@ -33,6 +34,10 @@ class Demopass::App
|
|
33
34
|
|
34
35
|
private
|
35
36
|
|
37
|
+
def path_excluded?(request)
|
38
|
+
@except && request.path =~ @except
|
39
|
+
end
|
40
|
+
|
36
41
|
def token_valid?(request)
|
37
42
|
request.cookies[TOKEN_KEY] == @valid_hmac
|
38
43
|
end
|
@@ -74,4 +79,12 @@ private
|
|
74
79
|
def respond_with_form
|
75
80
|
@response.write(FORM)
|
76
81
|
end
|
82
|
+
|
83
|
+
def validate_arguments
|
84
|
+
if @except && !@except.is_a?(Regexp)
|
85
|
+
raise Demopass::Error, "The `except` option must be a regular expression (or blank)."
|
86
|
+
end
|
87
|
+
|
88
|
+
raise Demopass::Error, "Please configure DEMOPASS_SECRET and DEMOPASS_PASSWORD" unless @hmac_key && @password
|
89
|
+
end
|
77
90
|
end
|
data/lib/demopass/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: demopass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Crosby-McCullough
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|