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 +4 -4
- data/lib/zaikio/jwt_auth.rb +9 -3
- data/lib/zaikio/jwt_auth/token_data.rb +18 -0
- data/lib/zaikio/jwt_auth/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: d7b4d20c732061b0d41453bfa9f8b6b92bbeb6ff07dc146d17b0fd833356ca4a
|
4
|
+
data.tar.gz: c18a3da38ad85e0a04915ef11f865de78ea358ee8fa456d1244dde0bb3809d46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df04a88a338e76b4ce746043e33ab172aa804d1e6b5079849325650ac0fe9f29f7c6d7b0aa9327e70f090b7e08c3acac21b9ad05da80356cf76c336c8f815d71
|
7
|
+
data.tar.gz: 58d19b43b1c68be4c983f3b03eaacac1d46ea3fdee6946b1151182ada650860c537761406db3352881103d5185b4827a835384de7288e4181174e856e1ca2da5
|
data/lib/zaikio/jwt_auth.rb
CHANGED
@@ -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 ||=
|
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
|
-
|
105
|
-
|
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|
|
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.
|
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-
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|