mumukit-auth 7.12.0 → 7.13.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/token.rb +48 -6
- 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: 5a77054a911454b7372cadecd8bda02e894ff80bd24ee5d19eb4b9086fb17dcc
|
|
4
|
+
data.tar.gz: 69b57019319e45c0a2c49425fea3964d9e270c5452c61c3f20d374ee41077464
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36a9d0459ed2513e94851f01312aab4ed88e8abcf17707c2c9c7bb3a86a9be406e8b5d43ac6d7194d568118622bb2801125aba27996c4eff7b12dd6824c538f6
|
|
7
|
+
data.tar.gz: e16a35c4478a206125c1d489b24ea79c84e0ba5d0082057363deb0d653c44d09e1bf7cc6e86f31268fad9b76d66c3d240eaf1b6f5643121dd7930f4765963289
|
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,13 @@ module Mumukit::Auth
|
|
|
23
39
|
client.encode jwt
|
|
24
40
|
end
|
|
25
41
|
|
|
26
|
-
def
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
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.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:
|
|
11
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|