minato-rails-auth 0.2.1 → 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: f852d8c8fb4a6ab7e5afa05144de2fcc622ac073e7830fa4f4229d9975941d78
4
- data.tar.gz: d8ad8fd69b33b1e952c363d9c149dba390f313b1168f0226678e78708efca5b3
3
+ metadata.gz: fd68460698a1370828ff45e5bb4836b116a7ad009117442d7648106819ce9020
4
+ data.tar.gz: bf643b4c8cd5caaec81f0d65ce9e1a65ae33bfdf5809fe600c8cd1ded02f7126
5
5
  SHA512:
6
- metadata.gz: 19744e2044ad31a4754435d0df1ab7cdff2233ce5ce8f36ad971ec0dc08544ca3506297ec04e55f5f50f0e5943e19f2bbd12b93633e42e586c34e336e6ff4959
7
- data.tar.gz: bcbfdec2e4b3b57c914e326e44d7e24490959d356bf838aca0a3a0a764880ba89b7982abe0edce4024502c75118a7bb53d82089628091d5ba7c73d3284e552bb
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,42 +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
- @human ||= @token_payload.respond_to?(:session)
17
+ session_obj&.identity.present?
17
18
  end
18
19
 
19
20
  def machine?
20
- @machine ||= !human?
21
+ !human?
22
+ end
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']
21
36
  end
22
37
 
23
38
  def identity
39
+ return nil if machine?
40
+
24
41
  return impersonator_identity unless impersonated?
25
42
 
26
- session.identity.metadata_public.impersonated_identity
43
+ session_obj.identity.metadata_public.impersonated_identity
27
44
  end
28
45
 
29
46
  def impersonator_identity
30
- session.identity
47
+ session_obj.identity
31
48
  end
32
49
 
33
50
  def subject
34
- @token_payload.sub
51
+ @token_payload_obj.sub
35
52
  end
36
53
 
37
54
  def impersonated?
38
- session.identity.metadata_public&.impersonated_identity.present?
55
+ return false if machine?
56
+
57
+ session_obj.identity.metadata_public&.impersonated_identity.present?
39
58
  end
40
59
 
41
60
  private
42
61
 
43
- def session
44
- @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?
45
76
  end
46
77
  end
47
78
  end
@@ -3,7 +3,7 @@
3
3
  module Minato
4
4
  module Rails
5
5
  module Auth
6
- VERSION = '0.2.1'
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.1
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-30 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