zaikio-jwt_auth 0.1.6 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7b4d20c732061b0d41453bfa9f8b6b92bbeb6ff07dc146d17b0fd833356ca4a
4
- data.tar.gz: c18a3da38ad85e0a04915ef11f865de78ea358ee8fa456d1244dde0bb3809d46
3
+ metadata.gz: aa5cedf782b4972795398012fb5d50f5156995a34951a077b49ab8c72d47af6c
4
+ data.tar.gz: 2e76b158eaddb1c7993412883fe0926af121ac1e959c8f0ff6e9fdc4a71fd17c
5
5
  SHA512:
6
- metadata.gz: df04a88a338e76b4ce746043e33ab172aa804d1e6b5079849325650ac0fe9f29f7c6d7b0aa9327e70f090b7e08c3acac21b9ad05da80356cf76c336c8f815d71
7
- data.tar.gz: 58d19b43b1c68be4c983f3b03eaacac1d46ea3fdee6946b1151182ada650860c537761406db3352881103d5185b4827a835384de7288e4181174e856e1ca2da5
6
+ metadata.gz: 0c837c489820a0bfe172813a22e0a974bb5686724826db11a76c88cf08085c2ca250124310dedc95146e640b6755ad32e18490a35cf617270c736ab63fbe46b1
7
+ data.tar.gz: da668d14415c81d38a08b8d1bed52390b7040476301ac049a43c63a8e96eb973b229ebd5ad689b215b244b99dd18edbc0e3ff78f24eb84d1245babb977b09cdf
@@ -107,7 +107,8 @@ module Zaikio
107
107
  def show_error_if_authorize_by_jwt_scopes_fails(token_data)
108
108
  return if token_data.scope_by_configurations?(
109
109
  self.class.authorize_by_jwt_scopes,
110
- action_name
110
+ action_name,
111
+ self
111
112
  )
112
113
 
113
114
  render_error("unpermitted_scope")
@@ -35,14 +35,16 @@ module Zaikio
35
35
 
36
36
  # scope_options is an array of objects with:
37
37
  # scope, app_name (optional), except/only (array, optional)
38
- def scope_by_configurations?(scope_configurations, action_name)
38
+ def scope_by_configurations?(scope_configurations, action_name, context)
39
39
  configuration = scope_configurations.find do |scope_configuration|
40
- if scope_configuration[:only]
41
- Array(scope_configuration[:only]).any? { |a| a.to_s == action_name }
42
- elsif scope_configuration[:except]
43
- Array(scope_configuration[:except]).none? { |a| a.to_s == action_name }
40
+ action_matches = action_matches_config?(scope_configuration, action_name)
41
+
42
+ if action_matches && scope_configuration[:if] && !context.instance_exec(&scope_configuration[:if])
43
+ false
44
+ elsif action_matches && scope_configuration[:unless] && context.instance_exec(&scope_configuration[:unless])
45
+ false
44
46
  else
45
- true
47
+ action_matches
46
48
  end
47
49
  end
48
50
 
@@ -51,6 +53,16 @@ module Zaikio
51
53
  scope?(configuration[:scopes], action_name, configuration[:app_name])
52
54
  end
53
55
 
56
+ def action_matches_config?(scope_configuration, action_name)
57
+ if scope_configuration[:only]
58
+ Array(scope_configuration[:only]).any? { |a| a.to_s == action_name }
59
+ elsif scope_configuration[:except]
60
+ Array(scope_configuration[:except]).none? { |a| a.to_s == action_name }
61
+ else
62
+ true
63
+ end
64
+ end
65
+
54
66
  def scope?(allowed_scopes, action_name, app_name = nil)
55
67
  app_name ||= Zaikio::JWTAuth.configuration.app_name
56
68
  Array(allowed_scopes).map(&:to_s).any? do |allowed_scope|
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module JWTAuth
3
- VERSION = "0.1.6".freeze
3
+ VERSION = "0.1.7".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crispy Mountain GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.1
33
+ version: 6.0.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.1
40
+ version: 6.0.2.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jwt
43
43
  requirement: !ruby/object:Gem::Requirement