panoptes-client 0.4.0 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/panoptes/client/authentication.rb +32 -18
- data/lib/panoptes/client/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b31b1558519ae640f4ee2504b01797b31ec3758526900bed1c52f0e355f210c
|
4
|
+
data.tar.gz: 87fef50c3aa0669ed3ba57d6acc423f5bfa1c7a2658ce90c2b6c7a038bcfabc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bdb6f370c994b60217d16c3f3ef01dc40d09c3b6cc0615fdaed9c044431cfbdd68b2d3ee6fa2a50736a42b303c91f6b1d55374c2e353f9bb44e04c3bb2f13c8
|
7
|
+
data.tar.gz: 1df9b85193256c608b06f21e24db4bea2105c6a74c605967bd3d6ce76c38a662a78dbc96837993246ab32ef594a6965a42d66800d325879ce4cdce729b4c3b5c
|
@@ -5,28 +5,28 @@ module Panoptes
|
|
5
5
|
module Authentication
|
6
6
|
extend Gem::Deprecate
|
7
7
|
|
8
|
+
attr_reader :payload
|
9
|
+
|
8
10
|
def jwt_payload
|
9
11
|
raise NotLoggedIn unless @auth[:token]
|
10
|
-
payload
|
11
|
-
payload
|
12
|
+
@payload = decode_token(@auth[:token])
|
12
13
|
rescue JWT::ExpiredSignature
|
13
14
|
raise AuthenticationExpired
|
14
15
|
end
|
15
16
|
|
16
17
|
def token_contents
|
17
|
-
if
|
18
|
-
|
19
|
-
|
20
|
-
@payload = jwt_payload
|
21
|
-
@expires_at = expiry_from_payload(@payload)
|
22
|
-
@payload.fetch('data', ())
|
18
|
+
if payload_exists? && !payload_expired?
|
19
|
+
# use the cached version of the payload while not expired
|
20
|
+
payload['data']
|
23
21
|
else
|
24
|
-
|
22
|
+
# decode the payload from the JWT token
|
23
|
+
jwt_payload['data']
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
27
|
def token_expiry
|
29
|
-
|
28
|
+
# always decode and fetch the expiry time from the JWT token
|
29
|
+
Time.at(jwt_payload.fetch('exp',0)).utc
|
30
30
|
end
|
31
31
|
|
32
32
|
def authenticated?
|
@@ -34,22 +34,22 @@ module Panoptes
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def authenticated_user_login
|
37
|
-
|
37
|
+
ensure_authenticated
|
38
38
|
token_contents.fetch('login', nil)
|
39
39
|
end
|
40
40
|
|
41
41
|
def authenticated_user_display_name
|
42
|
-
|
42
|
+
ensure_authenticated
|
43
43
|
token_contents.fetch('dname', nil)
|
44
44
|
end
|
45
45
|
|
46
46
|
def authenticated_user_id
|
47
|
-
|
47
|
+
ensure_authenticated
|
48
48
|
token_contents.fetch('id')
|
49
49
|
end
|
50
50
|
|
51
51
|
def authenticated_admin?
|
52
|
-
|
52
|
+
ensure_authenticated
|
53
53
|
token_contents.fetch('admin', false)
|
54
54
|
end
|
55
55
|
|
@@ -58,12 +58,26 @@ module Panoptes
|
|
58
58
|
end
|
59
59
|
deprecate :current_user, :token_contents, 2019, 7
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
private
|
62
|
+
|
63
|
+
def ensure_authenticated
|
64
|
+
raise NotLoggedIn unless authenticated?
|
65
|
+
end
|
66
|
+
|
67
|
+
def payload_exists?
|
68
|
+
!!@payload
|
69
|
+
end
|
70
|
+
|
71
|
+
def payload_expiry_time
|
72
|
+
@payload_expiry_time ||= Time.at(payload.fetch('exp',0)).utc
|
63
73
|
end
|
64
74
|
|
65
|
-
def
|
66
|
-
Time.
|
75
|
+
def payload_expired?
|
76
|
+
payload_expiry_time < Time.now.utc
|
77
|
+
end
|
78
|
+
|
79
|
+
def jwt_signing_public_key
|
80
|
+
@jwt_signing_public_key ||= OpenSSL::PKey::RSA.new(File.read(@public_key_path))
|
67
81
|
end
|
68
82
|
|
69
83
|
def decode_token(token)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panoptes-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-11-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: deprecate
|
@@ -200,12 +200,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
202
|
requirements:
|
203
|
-
- - "
|
203
|
+
- - ">"
|
204
204
|
- !ruby/object:Gem::Version
|
205
|
-
version:
|
205
|
+
version: 1.3.1
|
206
206
|
requirements: []
|
207
|
-
|
208
|
-
rubygems_version: 2.5.2
|
207
|
+
rubygems_version: 3.0.4
|
209
208
|
signing_key:
|
210
209
|
specification_version: 4
|
211
210
|
summary: API wrapper for https://panoptes.zooniverse.org
|