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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c1873c090d214598c8dfde394af11341cbe5ef5da1604479725e3ccab5a30fe
4
- data.tar.gz: 315c143eae6654332e7b3d1c13e74d5dfe24a29ecad5ae1063ef3ef7770f121a
3
+ metadata.gz: 600ea97ec7444992f512908fd046eace4f4fbe4cdf13438f0b5035e39f4de529
4
+ data.tar.gz: b0d7c15848351ab61c58e6a236ab998f5889f60921840e4c7381f7a521b3cbfe
5
5
  SHA512:
6
- metadata.gz: ef85cc04780ed65e32524bf1a3f59caabbe9222ea62340b1263c116ac058f06aaf8bac6478605a0b61511ddab04fbe82ee3252b113a8dea2a2bc7cd868ba3795
7
- data.tar.gz: dbddcd9a2a0f85d30135fca3b697b1c6a4e99ab8e492aaa81a34fa46b2e4965fd7e867675630aab1889c11650fa992b7c5a162837e906a7690cb2b9ba34ea81a
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
- @scopes = {}.with_indifferent_access
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
@@ -73,15 +73,18 @@ module Mumukit::Auth
73
73
  parent :editor
74
74
  end
75
75
  class Editor < Role
76
- parent :admin
76
+ parent :manager
77
77
  end
78
78
  class Janitor < Role
79
- parent :admin
79
+ parent :manager
80
80
  end
81
81
  class Moderator < Role
82
- parent :forum_supervisor
82
+ parent :supervisor
83
+ end
84
+ class Manager < Role
85
+ parent :supervisor
83
86
  end
84
- class ForumSupervisor < Role
87
+ class Supervisor < Role
85
88
  parent :admin
86
89
  end
87
90
  class Admin < Role
@@ -1,6 +1,13 @@
1
1
  module Mumukit::Auth
2
2
  module Roles
3
- ROLES = [:ex_student, :student, :teacher, :headmaster, :writer, :editor, :janitor, :moderator, :forum_supervisor, :admin, :owner]
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
-
@@ -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 self.from_rack_env(env)
27
- new(env.dig('omniauth.auth', 'extra', 'raw_info') || {})
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
-
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Auth
3
- VERSION = '7.12.0'
3
+ VERSION = '7.14.0'
4
4
  end
5
5
  end
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.12.0
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: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2022-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler