minato-rails-auth 0.2.2 → 0.2.3

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: 066ebdf4bb5c9974b2fb7081cb9a49b1f94cc7827bade857513537a189567eb6
4
- data.tar.gz: 9360a913dda2ef27b36e5ef6f5608b9f3663f5a9f0fbd14efcae7ef09575298f
3
+ metadata.gz: fd68460698a1370828ff45e5bb4836b116a7ad009117442d7648106819ce9020
4
+ data.tar.gz: bf643b4c8cd5caaec81f0d65ce9e1a65ae33bfdf5809fe600c8cd1ded02f7126
5
5
  SHA512:
6
- metadata.gz: 3d218d8a28492a771b5217c053975bcedc2c2435200c31ff28012d7ce6be28a2eff526221f7c5095bea55b1056ca8b764a5dc09a7fd13aadb9ae4580f8976e53
7
- data.tar.gz: 946d093736ee168f09a9bded1b94c5e78bd941ec5dad35d3b8e0af1150ef30d2161f2443fbc6f1f3dc1945a063d13ead5adc23a91d90ef89ba3efce8a285d257
6
+ metadata.gz: 0bac1061d4313611d88bee29320c440eb61c33b0e99f7e87923fd5d8b994a5a60df269d010f774af338250047ebe95d408b744560d1e0be5065638e7854e0798
7
+ data.tar.gz: 3ff04da825379e2ec3e07f258059651970ba89a1dd956dc27b0edefa5869098f5ded116ee6153f776b996f7ff242f3181090b4875190321b3e0f4e6e89168f69
data/.rubocop.yml CHANGED
@@ -37,4 +37,4 @@ Layout/HashAlignment:
37
37
  EnforcedHashRocketStyle: table
38
38
 
39
39
  RSpec/MultipleMemoizedHelpers:
40
- Max: 7
40
+ Max: 10
@@ -20,12 +20,23 @@ module Minato
20
20
  let(:jwt_account_id) { '555' }
21
21
  let(:jwt_session_id) { '67cf621f-4f49-4ca5-9365-62520849170b' }
22
22
  let(:jwt_identity_id) { 'adb1e688-17c0-4241-bc24-912fa6b5f6c3' }
23
+ let(:jwt_authentication_method) { 'password' }
24
+ let(:jwt_authentication_provider) { '' }
25
+ let(:jwt_authentication_methods) do
26
+ [
27
+ {
28
+ 'method' => jwt_authentication_method,
29
+ 'provider' => jwt_authentication_provider
30
+ }
31
+ ]
32
+ end
23
33
  let(:jwt_payload) do
24
34
  {
25
35
  'session' => {
26
- 'id' => jwt_session_id,
27
- 'expires_at' => '2021-09-29T20:15:44.731576Z',
28
- 'identity' => {
36
+ 'id' => jwt_session_id,
37
+ 'expires_at' => '2021-09-29T20:15:44.731576Z',
38
+ 'authentication_methods' => jwt_authentication_methods,
39
+ 'identity' => {
29
40
  'id' => jwt_identity_id,
30
41
  'traits' => {
31
42
  'email' => jwt_email
@@ -6,46 +6,73 @@ module Minato
6
6
  module Rails
7
7
  module Auth
8
8
  class User
9
- attr_reader :token_payload
9
+ attr_reader :token_payload_obj, :token_payload_raw
10
10
 
11
11
  def initialize(token_payload)
12
- @token_payload = ObjectHash.new(token_payload)
12
+ @token_payload_raw = token_payload
13
+ @token_payload_obj = ObjectHash.new(token_payload)
13
14
  end
14
15
 
15
16
  def human?
16
- session&.identity.present?
17
+ session_obj&.identity.present?
17
18
  end
18
19
 
19
20
  def machine?
20
21
  !human?
21
22
  end
22
23
 
24
+ def auth_sso?
25
+ authentication_method? 'oidc'
26
+ end
27
+
28
+ def auth_password?
29
+ authentication_method? 'password'
30
+ end
31
+
32
+ def auth_provider
33
+ return unless auth_sso?
34
+
35
+ authentication_method('oidc')['provider']
36
+ end
37
+
23
38
  def identity
24
39
  return nil if machine?
25
40
 
26
41
  return impersonator_identity unless impersonated?
27
42
 
28
- session.identity.metadata_public.impersonated_identity
43
+ session_obj.identity.metadata_public.impersonated_identity
29
44
  end
30
45
 
31
46
  def impersonator_identity
32
- session.identity
47
+ session_obj.identity
33
48
  end
34
49
 
35
50
  def subject
36
- @token_payload.sub
51
+ @token_payload_obj.sub
37
52
  end
38
53
 
39
54
  def impersonated?
40
55
  return false if machine?
41
56
 
42
- session.identity.metadata_public&.impersonated_identity.present?
57
+ session_obj.identity.metadata_public&.impersonated_identity.present?
43
58
  end
44
59
 
45
60
  private
46
61
 
47
- def session
48
- @token_payload.session
62
+ def session_obj
63
+ @token_payload_obj.session
64
+ end
65
+
66
+ def session_raw
67
+ @token_payload_raw['session']
68
+ end
69
+
70
+ def authentication_method(auth_method)
71
+ session_raw['authentication_methods']&.find { |m| m['method'].to_s == auth_method.to_s }
72
+ end
73
+
74
+ def authentication_method?(auth_method)
75
+ authentication_method(auth_method).present?
49
76
  end
50
77
  end
51
78
  end
@@ -3,7 +3,7 @@
3
3
  module Minato
4
4
  module Rails
5
5
  module Auth
6
- VERSION = '0.2.2'
6
+ VERSION = '0.2.3'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minato-rails-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferreri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-31 00:00:00.000000000 Z
11
+ date: 2024-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport