compeon-access_token 0.3.0 → 0.4.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: 5c83a325f189d8170cdb5fb9fcf020f4cd5492040fc6a87b31a05e74d67df661
4
- data.tar.gz: 3c1f2246d1dc267270443f86dc21f6418dd4b33085f96c45ac5004be59b37d81
3
+ metadata.gz: 0cc9d4474834d3d8f14b3de7fba0da4ada1ca28853808405ff2b1af80f7f7886
4
+ data.tar.gz: 0f02baf6512b4dd6bb0fde8fe481e6a795164827d4bb92c282fdb71b6254c38b
5
5
  SHA512:
6
- metadata.gz: 8d26055e1302ab75ec0739d17f5e9310062224f95df4f540ce049d5574c50e2c9d5d18959e52c887179f58a4504d16524c0cd5a945f8afd5d486781df108aa93
7
- data.tar.gz: 278d1e3e423f513717e022d42e613d43c9d0528f60644a5d4bc3db99b7ff5057dfae602e3e9a7ff92f03a0b0663b8da6d38558d0b84c0a76427764756f64b647
6
+ metadata.gz: dbc7b9b07c6348450b5e3ea2ddf1330b24e5c6f2f6542a02f4c239d950c5cbbeaa717d2dce6fbf337b4ee9c6fd02eccecf6789f2dfa9489fd41e79e0dc6fdf31
7
+ data.tar.gz: 6c5c5161559225af5c8e61b9861d324ecd41e7f578ea04a77b0ff421a6ca59b9f7a974d5207a8c87bdaac973593edbc9712c18b14922029d5d5cf342026f6d1e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compeon-access_token (0.3.0)
4
+ compeon-access_token (0.4.0)
5
5
  jwt (~> 2.1)
6
6
 
7
7
  GEM
@@ -9,15 +9,16 @@ module Compeon
9
9
  class AccessToken
10
10
  class ParseError < RuntimeError; end
11
11
 
12
- def initialize(role:, user_id:, kind:, client_id:, token:)
12
+ def initialize(role:, user_id:, kind:, client_id:, session_id: nil, token:)
13
13
  @role = role
14
14
  @user_id = user_id
15
15
  @kind = kind
16
16
  @client_id = client_id
17
+ @session_id = session_id
17
18
  @token = token
18
19
  end
19
20
 
20
- attr_reader :role, :user_id, :kind, :client_id, :token
21
+ attr_reader :role, :user_id, :kind, :client_id, :session_id, :token
21
22
 
22
23
  class << self
23
24
  attr_writer :environment
@@ -35,8 +36,9 @@ module Compeon
35
36
  user_id = data.fetch('uid')
36
37
  kind = data.fetch('knd')
37
38
  client_id = data.fetch('cid')
39
+ session_id = data.fetch('sid')
38
40
 
39
- new(role: role, user_id: user_id, kind: kind, client_id: client_id, token: token)
41
+ new(role: role, user_id: user_id, kind: kind, client_id: client_id, session_id: session_id, token: token)
40
42
  rescue JWT::DecodeError
41
43
  raise ParseError
42
44
  end
@@ -1,5 +1,5 @@
1
1
  module Compeon
2
2
  class AccessToken
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ module Compeon
4
4
  module Token
5
5
  class Access < Base
6
6
  class << self
7
- def attributes_mapping
7
+ def required_attributes_mapping
8
8
  {
9
9
  client_id: :cid,
10
10
  role: :role,
@@ -12,6 +12,10 @@ module Compeon
12
12
  }.freeze
13
13
  end
14
14
 
15
+ def optional_attributes_mapping
16
+ { session_id: :sid }.freeze
17
+ end
18
+
15
19
  def jwt_algorithm
16
20
  'RS256'
17
21
  end
@@ -21,13 +25,14 @@ module Compeon
21
25
  end
22
26
  end
23
27
 
24
- attr_accessor :client_id, :role, :user_id
28
+ attr_accessor :client_id, :role, :user_id, :session_id
25
29
 
26
- def initialize(client_id:, role:, user_id:, **claims)
30
+ def initialize(client_id:, role:, user_id:, session_id: nil, **claims)
27
31
  super(claims)
28
32
  @client_id = client_id
29
33
  @role = role
30
34
  @user_id = user_id
35
+ @session_id = session_id
31
36
  end
32
37
  end
33
38
  end
@@ -4,7 +4,7 @@ module Compeon
4
4
  module Token
5
5
  class Authorization < Base
6
6
  class << self
7
- def attributes_mapping
7
+ def required_attributes_mapping
8
8
  {
9
9
  client_id: :cid,
10
10
  redirect_uri: :uri,
@@ -12,6 +12,10 @@ module Compeon
12
12
  }.freeze
13
13
  end
14
14
 
15
+ def optional_attributes_mapping
16
+ { session_id: :sid }.freeze
17
+ end
18
+
15
19
  def jwt_algorithm
16
20
  'RS256'
17
21
  end
@@ -21,13 +25,14 @@ module Compeon
21
25
  end
22
26
  end
23
27
 
24
- attr_accessor :client_id, :redirect_uri, :user_id
28
+ attr_accessor :client_id, :redirect_uri, :user_id, :session_id
25
29
 
26
- def initialize(client_id:, redirect_uri:, user_id:, **claims)
30
+ def initialize(client_id:, redirect_uri:, user_id:, session_id: nil, **claims)
27
31
  super(claims)
28
32
  @client_id = client_id
29
33
  @redirect_uri = redirect_uri
30
34
  @user_id = user_id
35
+ @session_id = session_id
31
36
  end
32
37
  end
33
38
  end
@@ -10,6 +10,18 @@ module Compeon
10
10
  @attributes ||= attributes_mapping.keys.freeze
11
11
  end
12
12
 
13
+ def attributes_mapping
14
+ required_attributes_mapping.merge(optional_attributes_mapping).freeze
15
+ end
16
+
17
+ def required_attributes
18
+ @required_attributes ||= required_attributes_mapping.keys.freeze
19
+ end
20
+
21
+ def optional_attributes
22
+ @optional_attributes ||= optional_attributes_mapping.keys.freeze
23
+ end
24
+
13
25
  def registered_claims_mapping
14
26
  {
15
27
  audience: :aud,
@@ -65,7 +77,7 @@ module Compeon
65
77
  end
66
78
 
67
79
  def attributes_valid?
68
- self.class.attributes.none? { |accessor| public_send(accessor).nil? }
80
+ self.class.required_attributes.none? { |accessor| public_send(accessor).nil? }
69
81
  end
70
82
  end
71
83
  end
@@ -39,6 +39,7 @@ module Compeon
39
39
  .attributes_mapping
40
40
  .invert
41
41
  .transform_values { |attribute| token.public_send(attribute) }
42
+ .reject { |attribute, value| token.class.optional_attributes.include?(attribute) && value.nil? }
42
43
  end
43
44
  end
44
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compeon-access_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Schilling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt