jwt-authenticator 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a0f3e5579beda1099857bfb7731cf03f9a531f5178289ac89721561f51b9394
4
- data.tar.gz: b4d779f5919c2bcce341e484b720fe995eea90eb4d1dd1f7faa7fde9fa669293
3
+ metadata.gz: 0aaf041548d6b16756d9cadbccf38afa83f5eeaaa7954bc41f00c9a99c21ce12
4
+ data.tar.gz: 1e796bbd42368f5c76fbfe31416b847ebd983e76aa664cd051a8aedf119be754
5
5
  SHA512:
6
- metadata.gz: fc10f802cea4187f46f4c8ef876e8caf11010f8477fa2461d210d75a63cdfda109f711e320b8a4b2e06b7e22f0c86845a2cd4b1ce4f08189648f3e292488eda9
7
- data.tar.gz: 77512700bcc753b7505b82682595baeabc46b50cbff09cf1199ff4fb559e19143d106958f485051b77ed393c2eca1516cec85e84fd6cc734d66c175129e960fd
6
+ metadata.gz: a420c305744cb0e49dd685e9f572b5f2dc374e1fa0101fb836ae6440861f70113db30ba9ffca205aeaa584a5c5e579e3db23a7922abf731c673ef8cd20c84797
7
+ data.tar.gz: 336e1dccc210c359c7e94995eda94c24c45ce0a038287f82e1349deae4252a053f692dedb00dd251fc638191cff0f24118d49977564441a84f5be4dacede205c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jwt-authenticator (1.0.0)
4
+ jwt-authenticator (1.0.1)
5
5
  activesupport (>= 4.0, < 6.0)
6
6
  jwt (~> 2.1.0)
7
7
  method-not-implemented (~> 1.0.1)
@@ -14,7 +14,7 @@ class JWT::Authenticator
14
14
 
15
15
  def initialize
16
16
  @verification_options = token_verification_options_from_environment \
17
- self.class.name.split("::").first.underscore.upcase.gsub(/_?JWT\z/, "") + "_JWT"
17
+ self.class.name.split("::")[0...-1].join("_").underscore.upcase.gsub(/_?JWT\z/, "") + "_JWT"
18
18
  end
19
19
 
20
20
  def call(token)
@@ -33,19 +33,20 @@ protected
33
33
  method_not_implemented
34
34
  end
35
35
 
36
- def token_verification_options_from_environment(prefix)
37
- { verify_expiration: ENV["#{prefix}_VERIFY_EXP"] != "false",
38
- verify_not_before: ENV["#{prefix}_VERIFY_NBF"] != "false",
39
- iss: ENV["#{prefix}_ISS"].to_s.squish.presence,
40
- verify_iat: ENV["#{prefix}_VERIFY_IAT"] != "false",
41
- verify_jti: ENV["#{prefix}_VERIFY_JTI"] != "false",
42
- aud: ENV["#{prefix}_AUD"].to_s.split(",").map(&:squish).reject(&:blank?).presence, # Comma-separated values.
43
- sub: ENV["#{prefix}_SUB"].to_s.squish.presence,
44
- algorithms: ENV["#{prefix}_ALG"].to_s.split(",").map(&:squish).reject(&:blank?).presence, # Comma-separated values.
45
- leeway: ENV["#{prefix}_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? },
46
- iat_leeway: ENV["#{prefix}_IAT_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? },
47
- exp_leeway: ENV["#{prefix}_EXP_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? },
48
- nbf_leeway: ENV["#{prefix}_NBF_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? }
36
+ def token_verification_options_from_environment(namespace)
37
+ namespace = namespace.gsub(/_+\z/, "")
38
+ { verify_expiration: ENV["#{namespace}_VERIFY_EXP"] != "false",
39
+ verify_not_before: ENV["#{namespace}_VERIFY_NBF"] != "false",
40
+ iss: ENV["#{namespace}_ISS"].to_s.squish.presence,
41
+ verify_iat: ENV["#{namespace}_VERIFY_IAT"] != "false",
42
+ verify_jti: ENV["#{namespace}_VERIFY_JTI"] != "false",
43
+ aud: ENV["#{namespace}_AUD"].to_s.split(",").map(&:squish).reject(&:blank?).presence, # Comma-separated values.
44
+ sub: ENV["#{namespace}_SUB"].to_s.squish.presence,
45
+ algorithms: ENV["#{namespace}_ALG"].to_s.split(",").map(&:squish).reject(&:blank?).presence, # Comma-separated values.
46
+ leeway: ENV["#{namespace}_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? },
47
+ iat_leeway: ENV["#{namespace}_IAT_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? },
48
+ exp_leeway: ENV["#{namespace}_EXP_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? },
49
+ nbf_leeway: ENV["#{namespace}_NBF_LEEWAY"].to_s.squish.yield_self { |n| n.to_i if n.present? }
49
50
  }.tap { |options|
50
51
  options.merge! \
51
52
  verify_sub: options[:sub].present?,
@@ -3,6 +3,6 @@
3
3
 
4
4
  module JWT
5
5
  class Authenticator
6
- VERSION = "1.0.0"
6
+ VERSION = "1.0.1"
7
7
  end
8
8
  end
data/test/helper.rb CHANGED
@@ -40,3 +40,11 @@ module MyAPIv2
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ module MyAPI
45
+ module V3
46
+ class JWTAuthenticator < JWT::Authenticator
47
+
48
+ end
49
+ end
50
+ end
@@ -155,6 +155,12 @@ class JWTAuthenticatorTest < Test::Unit::TestCase
155
155
  assert_equal(103, error.code)
156
156
  end
157
157
 
158
+ test "loading token verification options from environment (authenticator nested under multiple modules)" do
159
+ ENV["MY_API_V3_JWT_ISS"] = "bar"
160
+ authenticator = MyAPI::V3::JWTAuthenticator.instance
161
+ assert_equal(ENV["MY_API_V3_JWT_ISS"], authenticator.instance_variable_get(:@verification_options)[:iss])
162
+ end
163
+
158
164
  private
159
165
 
160
166
  def my_api_v1_token_verification_options
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt-authenticator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Konoplov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-02 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -89,7 +89,7 @@ files:
89
89
  - lib/jwt-authenticator.rb
90
90
  - lib/jwt-authenticator/version.rb
91
91
  - test/helper.rb
92
- - test/jwt-authenticator-test.rb
92
+ - test/test-jwt-authenticator.rb
93
93
  homepage: https://github.com/ruby-jwt/jwt-authenticator
94
94
  licenses:
95
95
  - Apache-2.0
@@ -116,4 +116,4 @@ specification_version: 4
116
116
  summary: JSON Web Token authentication Ruby service.
117
117
  test_files:
118
118
  - test/helper.rb
119
- - test/jwt-authenticator-test.rb
119
+ - test/test-jwt-authenticator.rb