zaikio-jwt_auth 0.1.5 → 0.1.6

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: '0559a98a2221978a8a5c35e6968d667d9c17287b1421500ae0062bad169c0ece'
4
- data.tar.gz: be9a95f5684dd8329f1b5446400ad8704f46422a364de01675538f3001c0bf59
3
+ metadata.gz: d7b4d20c732061b0d41453bfa9f8b6b92bbeb6ff07dc146d17b0fd833356ca4a
4
+ data.tar.gz: c18a3da38ad85e0a04915ef11f865de78ea358ee8fa456d1244dde0bb3809d46
5
5
  SHA512:
6
- metadata.gz: d4f1a51bed19e09d9ca09eb873377639f6f197f289742d74e17a6d6fba3e130608547530ca65daa6ab40c3faad4a00a8b695582fee084d78b8e96e897165301f
7
- data.tar.gz: bf0eab6e6761239b33ae00d565ffc0b884fd70ddea3d589a91a0a1c7b2bf124e955048e8a5eebfbc7e42d1b37ed41fd96b0d6139b5f19ce5b60358bf69525612
6
+ metadata.gz: df04a88a338e76b4ce746043e33ab172aa804d1e6b5079849325650ac0fe9f29f7c6d7b0aa9327e70f090b7e08c3acac21b9ad05da80356cf76c336c8f815d71
7
+ data.tar.gz: 58d19b43b1c68be4c983f3b03eaacac1d46ea3fdee6946b1151182ada650860c537761406db3352881103d5185b4827a835384de7288e4181174e856e1ca2da5
@@ -49,7 +49,11 @@ module Zaikio
49
49
  end
50
50
 
51
51
  def authorize_by_jwt_scopes(scopes = nil, options = {})
52
- @authorize_by_jwt_scopes ||= options.merge(scopes: scopes)
52
+ @authorize_by_jwt_scopes ||= []
53
+
54
+ @authorize_by_jwt_scopes << options.merge(scopes: scopes) if scopes
55
+
56
+ @authorize_by_jwt_scopes
53
57
  end
54
58
  end
55
59
 
@@ -101,8 +105,10 @@ module Zaikio
101
105
  end
102
106
 
103
107
  def show_error_if_authorize_by_jwt_scopes_fails(token_data)
104
- scope_data = self.class.authorize_by_jwt_scopes
105
- return if !scope_data[:scopes] || token_data.scope?(scope_data[:scopes], action_name, scope_data[:app_name])
108
+ return if token_data.scope_by_configurations?(
109
+ self.class.authorize_by_jwt_scopes,
110
+ action_name
111
+ )
106
112
 
107
113
  render_error("unpermitted_scope")
108
114
  end
@@ -33,6 +33,24 @@ module Zaikio
33
33
  @payload["jti"]
34
34
  end
35
35
 
36
+ # scope_options is an array of objects with:
37
+ # scope, app_name (optional), except/only (array, optional)
38
+ def scope_by_configurations?(scope_configurations, action_name)
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 }
44
+ else
45
+ true
46
+ end
47
+ end
48
+
49
+ return true unless configuration
50
+
51
+ scope?(configuration[:scopes], action_name, configuration[:app_name])
52
+ end
53
+
36
54
  def scope?(allowed_scopes, action_name, app_name = nil)
37
55
  app_name ||= Zaikio::JWTAuth.configuration.app_name
38
56
  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.5".freeze
3
+ VERSION = "0.1.6".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.5
4
+ version: 0.1.6
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-14 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj