zaikio-jwt_auth 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24a55aebbcd25c1acc7790af95ca9d7eed70267607d498631681126cc1079702
4
- data.tar.gz: 82dbef152c4af9353713a68093c1f685ae219171146a8ebcc66e22fc43468f23
3
+ metadata.gz: c24518cc88a6fd45b415882497799e08ba4e9f8962a59b58e6bf80a0e3a79478
4
+ data.tar.gz: 04ceb1db55359f0a7a1506efd9df3b20f77de892a11e61fc19f4c28ba3492792
5
5
  SHA512:
6
- metadata.gz: 36797c903b57e7c56c65d370461b4da805300359629e4a96fca596e8a33d1e66e3e27d3652503d3bcc30eea1369d6fc3c6906254dd7e57b4591f449f38cae79e
7
- data.tar.gz: c18622291458097280a0ecd9d71a01dbd8138b6f3d469aadfe6dc261bb03a4f0a240262c834922174af33e66f6392522383dc62d79ab21418842ee6487e2e700
6
+ metadata.gz: 1b89cff570d1274a8b3c06311f67ddd487725ddca9d7cd8d098e5a174b025a1d9f9e811348d2b3dd9c5bd1f0d9bb67999bdd67e85b321dc704c3489412b31ff8
7
+ data.tar.gz: c1ebdd6aeb037503643b5704bd3682d4d64c62b62fc2d316f9480797069136d1d1e042de1244db714edcd01c2fa69af6ba6cdb31bf18c97a1e8426b25c05846c
@@ -11,7 +11,7 @@ module Zaikio
11
11
  production: "https://hub.zaikio.com"
12
12
  }.freeze
13
13
 
14
- attr_accessor :app_name, :cache, :host
14
+ attr_accessor :app_name, :cache, :host, :test_mode
15
15
  attr_reader :environment
16
16
  attr_writer :logger, :revoked_token_ids, :keys
17
17
 
@@ -19,6 +19,7 @@ module Zaikio
19
19
  @environment = :sandbox
20
20
  @revoked_token_ids = nil
21
21
  @keys = nil
22
+ @test_mode = false
22
23
  end
23
24
 
24
25
  def logger
@@ -10,7 +10,10 @@ module Zaikio
10
10
  class << self
11
11
  def loader
12
12
  lambda do |options|
13
+ return TestHelper.jwk_set if JWTAuth.configuration.test_mode
14
+
13
15
  reload_keys if options[:invalidate]
16
+
14
17
  {
15
18
  keys: keys.map do |key_data|
16
19
  JWT::JWK.import(key_data.with_indifferent_access).export
@@ -1,13 +1,36 @@
1
1
  module Zaikio
2
2
  module JWTAuth
3
3
  module TestHelper
4
+ def self.jwk
5
+ @jwk ||= JWT::JWK.new(OpenSSL::PKey::RSA.new(2048), { kid: "test-kid", use: "sig", alg: "RS256" })
6
+ end
7
+
8
+ def self.jwk_set
9
+ @jwk_set ||= JWT::JWK::Set.new(jwk).export
10
+ end
11
+
12
+
13
+
4
14
  def after_teardown
5
15
  Zaikio::JWTAuth.mocked_jwt_payload = nil
6
16
  super
7
17
  end
8
18
 
9
- def mock_jwt(extra_payload)
10
- Zaikio::JWTAuth.mocked_jwt_payload = {
19
+ def mock_jwt(params)
20
+ Zaikio::JWTAuth.mocked_jwt_payload = generate_token_payload(params)
21
+ end
22
+
23
+ def issue_mock_jwt_token(params)
24
+ JWT.encode(
25
+ generate_token_payload(params),
26
+ jwk.signing_key,
27
+ jwk[:alg],
28
+ kid: jwk[:kid]
29
+ )
30
+ end
31
+
32
+ def generate_token_payload(params)
33
+ {
11
34
  iss: "ZAI",
12
35
  sub: nil,
13
36
  aud: %w[test_app],
@@ -16,8 +39,10 @@ module Zaikio
16
39
  exp: 1.hour.from_now.to_i,
17
40
  jku: "http://hub.zaikio.test/api/v1/jwt_public_keys.json",
18
41
  scope: []
19
- }.merge(extra_payload).stringify_keys
42
+ }.merge(params).stringify_keys
20
43
  end
44
+
45
+ def jwk = Zaikio::JWTAuth::TestHelper.jwk
21
46
  end
22
47
  end
23
48
  end
@@ -21,8 +21,13 @@ module Zaikio
21
21
  }
22
22
  end
23
23
 
24
- def initialize(payload)
24
+ def initialize(payload, token: nil)
25
25
  @payload = payload
26
+ @token = token
27
+ end
28
+
29
+ def to_s
30
+ @token
26
31
  end
27
32
 
28
33
  def audience
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module JWTAuth
3
- VERSION = "2.7.0".freeze
3
+ VERSION = "2.8.0".freeze
4
4
  end
5
5
  end
@@ -72,7 +72,13 @@ module Zaikio
72
72
 
73
73
  payload, = JWT.decode(token, nil, true, **options)
74
74
 
75
- TokenData.new(payload)
75
+ TokenData.new(payload, token: token)
76
+ end
77
+
78
+ def self.decode_jwt(token, **options)
79
+ options = options.reverse_merge(algorithms: ["RS256"], jwks: JWK.loader)
80
+ payload, = JWT.decode(token, nil, true, **options)
81
+ TokenData.new(payload, token: token)
76
82
  end
77
83
 
78
84
  module ClassMethods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crispymtn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-07-03 00:00:00.000000000 Z
13
+ date: 2023-09-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activejob
@@ -68,7 +68,7 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: 2.2.1
71
- description: JWT-Based authentication and authorization with zaikio.
71
+ description: JWT-Based authentication and authorization with Zaikio.
72
72
  email:
73
73
  - op@crispymtn.com
74
74
  - js@crispymtn.com
@@ -117,5 +117,5 @@ requirements: []
117
117
  rubygems_version: 3.3.11
118
118
  signing_key:
119
119
  specification_version: 4
120
- summary: JWT-Based authentication and authorization with zaikio
120
+ summary: JWT-Based authentication and authorization with Zaikio
121
121
  test_files: []