panoptes-client 0.4.0 → 1.0.0.pre

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
- SHA1:
3
- metadata.gz: 738ea26bbdcac1cfd64a537f11210c5dbce0fb18
4
- data.tar.gz: 03143cbb89f128160b9659f744572d1bfa05986c
2
+ SHA256:
3
+ metadata.gz: 4b31b1558519ae640f4ee2504b01797b31ec3758526900bed1c52f0e355f210c
4
+ data.tar.gz: 87fef50c3aa0669ed3ba57d6acc423f5bfa1c7a2658ce90c2b6c7a038bcfabc5
5
5
  SHA512:
6
- metadata.gz: 8570661b211f00b0f20ab1b076ab1c033d467c89a495e8b4062081e4c6eb246b57555c76ba449d5e16c08b1674b28a778740f11dbb88ec011f15e803c82e0e4a
7
- data.tar.gz: fd0d5ebb58e5521b884abbe5723e2a09c6c69603f829d38b74e6f43fa40750662b646765edd37945f7e88b0f730ef7e45172ee7d53df4e890f7a3c7fd33b04c9
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, = decode_token(@auth[:token])
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 !@payload.nil? && expiry_from_payload(@payload) > Time.now.utc
18
- @payload.fetch('data', {})
19
- elsif @payload.nil?
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
- raise AuthenticationExpired
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
- @expires_at || expiry_from_payload(jwt_payload)
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
- raise NotLoggedIn unless authenticated?
37
+ ensure_authenticated
38
38
  token_contents.fetch('login', nil)
39
39
  end
40
40
 
41
41
  def authenticated_user_display_name
42
- raise NotLoggedIn unless authenticated?
42
+ ensure_authenticated
43
43
  token_contents.fetch('dname', nil)
44
44
  end
45
45
 
46
46
  def authenticated_user_id
47
- raise NotLoggedIn unless authenticated?
47
+ ensure_authenticated
48
48
  token_contents.fetch('id')
49
49
  end
50
50
 
51
51
  def authenticated_admin?
52
- raise NotLoggedIn unless authenticated?
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
- def jwt_signing_public_key
62
- @jwt_signing_public_key ||= OpenSSL::PKey::RSA.new(File.read(@public_key_path))
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 expiry_from_payload(payload)
66
- Time.at(payload.fetch('exp',0)).utc
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)
@@ -1,5 +1,5 @@
1
1
  module Panoptes
2
2
  class Client
3
- VERSION = "0.4.0".freeze
3
+ VERSION = '1.0.0.pre'.freeze
4
4
  end
5
5
  end
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.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-03-11 00:00:00.000000000 Z
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: '0'
205
+ version: 1.3.1
206
206
  requirements: []
207
- rubyforge_project:
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