mumukit-auth 7.12.0 → 7.14.0
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/mumukit/auth/permissions.rb +5 -1
- data/lib/mumukit/auth/role.rb +7 -4
- data/lib/mumukit/auth/roles.rb +8 -2
- data/lib/mumukit/auth/token.rb +44 -12
- data/lib/mumukit/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: 600ea97ec7444992f512908fd046eace4f4fbe4cdf13438f0b5035e39f4de529
|
4
|
+
data.tar.gz: b0d7c15848351ab61c58e6a236ab998f5889f60921840e4c7381f7a521b3cbfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04de29634c9fc0910e4f57af3d9be417e83f4b0ac8c23db94a0b21dc2edd6fe162f39b85dee9ee39f9030df59314caf90d5f041db1a43311c1decd0bc37e6b8d
|
7
|
+
data.tar.gz: 69228424458087b021989753f7420f1479b90626fb02262d626cbe18f2f6b4cbdcb053a58d324cbd2d28cdd0994a8fa34ae2b2dee93495cd0d2ee8c5fdb552eb
|
@@ -5,7 +5,7 @@ class Mumukit::Auth::Permissions
|
|
5
5
|
attr_accessor :scopes
|
6
6
|
|
7
7
|
def initialize(scopes={})
|
8
|
-
|
8
|
+
clear!
|
9
9
|
add_scopes! scopes
|
10
10
|
end
|
11
11
|
|
@@ -132,6 +132,10 @@ class Mumukit::Auth::Permissions
|
|
132
132
|
raise Mumukit::Auth::UnauthorizedAccessError unless assign_to?(self.class.reparse(other), previous)
|
133
133
|
end
|
134
134
|
|
135
|
+
def clear!
|
136
|
+
@scopes = {}.with_indifferent_access
|
137
|
+
end
|
138
|
+
|
135
139
|
def as_set
|
136
140
|
Set.new scopes.flat_map { |role, scope| scope.grants.map {|grant| [role, grant]} }
|
137
141
|
end
|
data/lib/mumukit/auth/role.rb
CHANGED
@@ -73,15 +73,18 @@ module Mumukit::Auth
|
|
73
73
|
parent :editor
|
74
74
|
end
|
75
75
|
class Editor < Role
|
76
|
-
parent :
|
76
|
+
parent :manager
|
77
77
|
end
|
78
78
|
class Janitor < Role
|
79
|
-
parent :
|
79
|
+
parent :manager
|
80
80
|
end
|
81
81
|
class Moderator < Role
|
82
|
-
parent :
|
82
|
+
parent :supervisor
|
83
|
+
end
|
84
|
+
class Manager < Role
|
85
|
+
parent :supervisor
|
83
86
|
end
|
84
|
-
class
|
87
|
+
class Supervisor < Role
|
85
88
|
parent :admin
|
86
89
|
end
|
87
90
|
class Admin < Role
|
data/lib/mumukit/auth/roles.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module Mumukit::Auth
|
2
2
|
module Roles
|
3
|
-
|
3
|
+
FINE_GRAINED_ROLES = [
|
4
|
+
:ex_student, :student, :teacher, :headmaster, :writer, :editor, :janitor,
|
5
|
+
:moderator, :manager
|
6
|
+
]
|
7
|
+
COARSE_GRAINED_ROLES = [:supervisor, :admin, :owner]
|
8
|
+
|
9
|
+
ROLES = COARSE_GRAINED_ROLES + FINE_GRAINED_ROLES
|
10
|
+
|
4
11
|
|
5
12
|
ROLES.each do |role|
|
6
13
|
define_method "#{role}?" do |scope = Mumukit::Auth::Slug.any|
|
@@ -9,4 +16,3 @@ module Mumukit::Auth
|
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
12
|
-
|
data/lib/mumukit/auth/token.rb
CHANGED
@@ -2,7 +2,7 @@ module Mumukit::Auth
|
|
2
2
|
class Token
|
3
3
|
attr_reader :jwt, :client
|
4
4
|
|
5
|
-
def initialize(jwt, client)
|
5
|
+
def initialize(jwt = {}, client = Mumukit::Auth::Client.new)
|
6
6
|
@jwt = jwt
|
7
7
|
@client = client
|
8
8
|
end
|
@@ -15,6 +15,22 @@ module Mumukit::Auth
|
|
15
15
|
@uid ||= jwt['uid'] || jwt['email'] || jwt['sub']
|
16
16
|
end
|
17
17
|
|
18
|
+
def organization
|
19
|
+
@organization ||= jwt['org']
|
20
|
+
end
|
21
|
+
|
22
|
+
def expiration
|
23
|
+
@expiration ||= Time.at jwt['exp']
|
24
|
+
end
|
25
|
+
|
26
|
+
def subject_id
|
27
|
+
@subject_id ||= jwt['sbid']
|
28
|
+
end
|
29
|
+
|
30
|
+
def subject_type
|
31
|
+
@subject_type ||= jwt['sbt']
|
32
|
+
end
|
33
|
+
|
18
34
|
def verify_client!
|
19
35
|
raise Mumukit::Auth::InvalidTokenError.new('aud mismatch') if client.id != jwt['aud']
|
20
36
|
end
|
@@ -23,12 +39,8 @@ module Mumukit::Auth
|
|
23
39
|
client.encode jwt
|
24
40
|
end
|
25
41
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.encode(uid, metadata, client = Mumukit::Auth::Client.new)
|
31
|
-
new({aud: client.id, metadata: metadata, uid: uid}, client).encode
|
42
|
+
def encode_header
|
43
|
+
'Bearer ' + encode
|
32
44
|
end
|
33
45
|
|
34
46
|
def self.decode(encoded, client = Mumukit::Auth::Client.new)
|
@@ -37,10 +49,6 @@ module Mumukit::Auth
|
|
37
49
|
raise Mumukit::Auth::InvalidTokenError.new(e)
|
38
50
|
end
|
39
51
|
|
40
|
-
def self.encode_header(uid, metadata)
|
41
|
-
'Bearer ' + encode(uid, metadata)
|
42
|
-
end
|
43
|
-
|
44
52
|
def self.decode_header(header, client = Mumukit::Auth::Client.new)
|
45
53
|
decode extract_from_header(header), client
|
46
54
|
end
|
@@ -50,6 +58,30 @@ module Mumukit::Auth
|
|
50
58
|
header.split(' ').last
|
51
59
|
end
|
52
60
|
|
61
|
+
def self.build(uid, client = Mumukit::Auth::Client.new,
|
62
|
+
expiration: nil, organization: nil,
|
63
|
+
subject_id: nil, subject_type: nil,
|
64
|
+
metadata: {})
|
65
|
+
new({
|
66
|
+
'uid' => uid,
|
67
|
+
'aud' => client.id,
|
68
|
+
'exp' => expiration&.to_i,
|
69
|
+
'org' => organization,
|
70
|
+
'metadata' => metadata,
|
71
|
+
'sbid' => subject_id,
|
72
|
+
'sbt' => subject_type
|
73
|
+
}.compact,
|
74
|
+
client)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.load(encoded)
|
78
|
+
if encoded.present?
|
79
|
+
decode encoded rescue nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.dump(decoded)
|
84
|
+
decoded.encode
|
85
|
+
end
|
53
86
|
end
|
54
87
|
end
|
55
|
-
|
data/lib/mumukit/auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumukit-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|