mumukit-auth 7.12.0 → 7.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c1873c090d214598c8dfde394af11341cbe5ef5da1604479725e3ccab5a30fe
4
- data.tar.gz: 315c143eae6654332e7b3d1c13e74d5dfe24a29ecad5ae1063ef3ef7770f121a
3
+ metadata.gz: 5a77054a911454b7372cadecd8bda02e894ff80bd24ee5d19eb4b9086fb17dcc
4
+ data.tar.gz: 69b57019319e45c0a2c49425fea3964d9e270c5452c61c3f20d374ee41077464
5
5
  SHA512:
6
- metadata.gz: ef85cc04780ed65e32524bf1a3f59caabbe9222ea62340b1263c116ac058f06aaf8bac6478605a0b61511ddab04fbe82ee3252b113a8dea2a2bc7cd868ba3795
7
- data.tar.gz: dbddcd9a2a0f85d30135fca3b697b1c6a4e99ab8e492aaa81a34fa46b2e4965fd7e867675630aab1889c11650fa992b7c5a162837e906a7690cb2b9ba34ea81a
6
+ metadata.gz: 36a9d0459ed2513e94851f01312aab4ed88e8abcf17707c2c9c7bb3a86a9be406e8b5d43ac6d7194d568118622bb2801125aba27996c4eff7b12dd6824c538f6
7
+ data.tar.gz: e16a35c4478a206125c1d489b24ea79c84e0ba5d0082057363deb0d653c44d09e1bf7cc6e86f31268fad9b76d66c3d240eaf1b6f5643121dd7930f4765963289
@@ -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,13 @@ 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') || {})
42
+ def encode_header
43
+ 'Bearer ' + encode
28
44
  end
29
45
 
30
46
  def self.encode(uid, metadata, client = Mumukit::Auth::Client.new)
31
- new({aud: client.id, metadata: metadata, uid: uid}, client).encode
47
+ warn "Deprecated: please use build and then encode"
48
+ build(uid, client, metadata: metadata).encode
32
49
  end
33
50
 
34
51
  def self.decode(encoded, client = Mumukit::Auth::Client.new)
@@ -38,7 +55,8 @@ module Mumukit::Auth
38
55
  end
39
56
 
40
57
  def self.encode_header(uid, metadata)
41
- 'Bearer ' + encode(uid, metadata)
58
+ warn "Deprecated: please use build and then encode_header"
59
+ 'Bearer ' + build(uid, metadata: metadata).encode_header
42
60
  end
43
61
 
44
62
  def self.decode_header(header, client = Mumukit::Auth::Client.new)
@@ -50,6 +68,30 @@ module Mumukit::Auth
50
68
  header.split(' ').last
51
69
  end
52
70
 
71
+ def self.build(uid, client = Mumukit::Auth::Client.new,
72
+ expiration: nil, organization: nil,
73
+ subject_id: nil, subject_type: nil,
74
+ metadata: {})
75
+ new({
76
+ 'uid' => uid,
77
+ 'aud' => client.id,
78
+ 'exp' => expiration&.to_i,
79
+ 'org' => organization,
80
+ 'metadata' => metadata,
81
+ 'sbid' => subject_id,
82
+ 'sbt' => subject_type
83
+ }.compact,
84
+ client)
85
+ end
86
+
87
+ def self.load(encoded)
88
+ if encoded.present?
89
+ decode encoded rescue nil
90
+ end
91
+ end
92
+
93
+ def self.dump(decoded)
94
+ decoded.encode
95
+ end
53
96
  end
54
97
  end
55
-
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Auth
3
- VERSION = '7.12.0'
3
+ VERSION = '7.13.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.13.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-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler