apiphobic-tokens 1.0.1 → 1.1.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: 4030c1789098ddaa92ba453c07fad65e895e9abcebe7c2ef6087c8ec0f7f3f47
4
- data.tar.gz: 72f570aaaf61e7d2f80f272a9988b415bc2b6837f267c0925d21185934d5ab0e
3
+ metadata.gz: ae8a5780d2cdb2f8b53a9f2cbafb3a6babe879f1f95427c7864dbbe9f55ffdcd
4
+ data.tar.gz: 34234f4f2b5f5aa5d5c5d5ee7bb8e33521d19e47a0c72e106dbad0daf9ba61bf
5
5
  SHA512:
6
- metadata.gz: 210c77fa2424697f7773975a346e386833598456f17a3583c4939da775ec9468dbf45d5d5b5cef5b702420b7870ee39e961666b6391152ab45e981ac7d414980
7
- data.tar.gz: 9e1551a52affe49184c314a5c5e07bb2a4df22f2063b4bdefe4986b52e28e9ce7abf446177d7a8a4aa60d76e7727041ea37efdd9dcd9bda30d238031e753426e
6
+ metadata.gz: 8cf66ae1fc76c0ee1aa654d2a0b0ef0fbc24a5012d265bed9f1d713bf79f8875706cfd264ba746d6009816d659c626edd7d47d5a5a740bdd6371258fbff5baf8
7
+ data.tar.gz: e3375f866acf219df3ded1404d92fc3c7d656fbb6db0f66f71b134473725d0170328c5b0210f5dd19392fe7d6d3179039f65a2251dc17e574d6ce88efbbe56b6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -39,7 +39,7 @@ module Tokens
39
39
  end
40
40
 
41
41
  def default_audience
42
- @default_audience || 'public'
42
+ @default_audience || 'User'
43
43
  end
44
44
 
45
45
  def default_availability_leeway_in_seconds
@@ -63,7 +63,7 @@ module Tokens
63
63
  end
64
64
 
65
65
  def default_subject
66
- @default_subject || 'User'
66
+ @default_subject || nil
67
67
  end
68
68
 
69
69
  def private_key
@@ -50,28 +50,26 @@ class JsonWebToken
50
50
  # rubocop:disable Metrics/ParameterLists, Metrics/LineLength
51
51
  def self.build(id: SecureRandom.uuid,
52
52
  audience: configuration.default_audience,
53
+ audience_id:,
53
54
  expiration: Time.now.utc.to_i + (60 * configuration.default_expiration_in_minutes),
54
55
  issuer: configuration.default_issuer,
55
56
  issued_at: Time.now.utc,
56
57
  not_before: Time.now.utc,
57
- owner: nil,
58
58
  roles: configuration.default_roles,
59
59
  subject: configuration.default_subject,
60
- subject_id:,
60
+ subject_id: nil,
61
61
  token_private_key: configuration.private_key)
62
62
 
63
- owner ||= subject_id
64
-
65
63
  new(
66
64
  private_key: token_private_key,
67
65
  data: {
66
+ 'aid' => audience_id,
68
67
  'aud' => audience,
69
68
  'exp' => expiration.to_i,
70
69
  'iat' => issued_at.to_i,
71
70
  'iss' => issuer,
72
71
  'jti' => id,
73
72
  'nbf' => not_before.to_i,
74
- 'own' => owner,
75
73
  'rol' => roles.join(','),
76
74
  'sid' => subject_id,
77
75
  'sub' => subject,
@@ -151,6 +149,10 @@ class JsonWebToken
151
149
  data['aud']
152
150
  end
153
151
 
152
+ def audience_id
153
+ data['aid']
154
+ end
155
+
154
156
  def issued_at
155
157
  data['iat']
156
158
  end
@@ -179,10 +181,6 @@ class JsonWebToken
179
181
  Time.at(not_before)
180
182
  end
181
183
 
182
- def owner_id
183
- data['own']
184
- end
185
-
186
184
  def subject_id
187
185
  data['sid']
188
186
  end
@@ -15,6 +15,10 @@ class Null < Tokens::Null
15
15
  nil
16
16
  end
17
17
 
18
+ def audience_id
19
+ nil
20
+ end
21
+
18
22
  def issued_at
19
23
  nil
20
24
  end
@@ -35,10 +39,6 @@ class Null < Tokens::Null
35
39
  nil
36
40
  end
37
41
 
38
- def owner_id
39
- nil
40
- end
41
-
42
42
  def subject_id
43
43
  nil
44
44
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apiphobic/tokens/json_web_token'
4
+
5
+ module Apiphobic
6
+ module Tokens
7
+ module JsonWebTokens
8
+ class Object < JsonWebToken
9
+ def self.build(object:,
10
+ expiration: Time.now.utc.to_i + (60 * 60 * 24 * 7),
11
+ **attrs)
12
+
13
+ super(subject: object.class.name,
14
+ subject_id: object.id,
15
+ expiration: expiration,
16
+ **attrs)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -8,9 +8,10 @@ module JsonWebTokens
8
8
  class PasswordReset < JsonWebToken
9
9
  def self.build(expiration: Time.now.utc.to_i + (30 * 60),
10
10
  roles: %w{password_reset},
11
+ subject: 'Password',
11
12
  **attrs)
12
13
 
13
- super(expiration: expiration, roles: roles, **attrs)
14
+ super(expiration: expiration, roles: roles, subject: subject, **attrs)
14
15
  end
15
16
  end
16
17
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apiphobic
4
4
  module Tokens
5
- VERSION = '1.0.1'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiphobic-tokens
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,7 +31,7 @@ cert_chain:
31
31
  Y2GAoHKstmfIVhc4XHOPpmTd2o/C29O9oaRgjrkfQEhF/KvJ/PhoV5hvokzsCyI5
32
32
  iUeXPfvrGD/itYIBCgk+fnzyQQ4QtE5hTQaWQ3o2
33
33
  -----END CERTIFICATE-----
34
- date: 2018-05-03 00:00:00.000000000 Z
34
+ date: 2018-05-25 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json-jwt
@@ -126,6 +126,7 @@ files:
126
126
  - lib/apiphobic/tokens/json_web_token.rb
127
127
  - lib/apiphobic/tokens/json_web_tokens/invalid.rb
128
128
  - lib/apiphobic/tokens/json_web_tokens/null.rb
129
+ - lib/apiphobic/tokens/json_web_tokens/object.rb
129
130
  - lib/apiphobic/tokens/json_web_tokens/password_reset.rb
130
131
  - lib/apiphobic/tokens/null.rb
131
132
  - lib/apiphobic/tokens/role_predicable.rb
metadata.gz.sig CHANGED
Binary file