minato-rails-auth 0.2.2 → 0.3.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: 066ebdf4bb5c9974b2fb7081cb9a49b1f94cc7827bade857513537a189567eb6
4
- data.tar.gz: 9360a913dda2ef27b36e5ef6f5608b9f3663f5a9f0fbd14efcae7ef09575298f
3
+ metadata.gz: 2bc480997642145dc7ea8fd7949781a14742aabae45cab0049b6ce076f0bd754
4
+ data.tar.gz: 18bb1bc2d7d9abc72e0d5e0d0802fe9a8121472f3d970f49138e0e4ff8cd757a
5
5
  SHA512:
6
- metadata.gz: 3d218d8a28492a771b5217c053975bcedc2c2435200c31ff28012d7ce6be28a2eff526221f7c5095bea55b1056ca8b764a5dc09a7fd13aadb9ae4580f8976e53
7
- data.tar.gz: 946d093736ee168f09a9bded1b94c5e78bd941ec5dad35d3b8e0af1150ef30d2161f2443fbc6f1f3dc1945a063d13ead5adc23a91d90ef89ba3efce8a285d257
6
+ metadata.gz: 62691cddf8bea24d687d4222e26ab2439794910c2e3f2c4362098676e0d71b2ef0fe407da3edcfc16dbb7e3b66aabfa788da67aa62114790ceab6137cdab5f26
7
+ data.tar.gz: 34f55655a7b14fdf11976542499eeb2d49d6533785b7411f62ad426b9f1cf23efe5d7663780f6edd50408cd293fbad6f87af6232d1d9aed672cf2bedc431b0c1
data/.rubocop.yml CHANGED
@@ -8,7 +8,7 @@ AllCops:
8
8
  DisplayStyleGuide: true
9
9
  ExtraDetails: false
10
10
  NewCops: enable
11
- TargetRubyVersion: 2.7.3
11
+ TargetRubyVersion: 3.2
12
12
 
13
13
  Metrics/BlockLength:
14
14
  AllowedMethods: ['describe', 'it', 'context']
@@ -26,9 +26,6 @@ RSpec/ImplicitExpect:
26
26
  RSpec/MultipleExpectations:
27
27
  Enabled: false
28
28
 
29
- RSpec/VerifiedDoubleReference:
30
- EnforcedStyle: string
31
-
32
29
  Style/Documentation:
33
30
  Enabled: false
34
31
 
@@ -37,4 +34,4 @@ Layout/HashAlignment:
37
34
  EnforcedHashRocketStyle: table
38
35
 
39
36
  RSpec/MultipleMemoizedHelpers:
40
- Max: 7
37
+ Max: 10
data/compose.yml CHANGED
@@ -2,7 +2,7 @@ services:
2
2
  minato-rails-auth:
3
3
  environment:
4
4
  GITLAB_AUTH_TOKEN: ${GITLAB_AUTH_TOKEN}
5
- image: ruby:2.7.3
5
+ image: us-east1-docker.pkg.dev/minato-cloud/images/ruby-minato:1.0.0-dev
6
6
  working_dir: /usr/src/api
7
7
  volumes:
8
8
  - .:/usr/src/api:z
@@ -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
@@ -3,10 +3,10 @@
3
3
  require_relative 'user'
4
4
  require_relative 'configuration'
5
5
  require_relative 'jwt/decode'
6
- require 'active_support'
7
6
  require 'net/http'
8
7
  require 'uri'
9
8
  require 'jwt'
9
+ require 'active_support/core_ext/object/blank'
10
10
 
11
11
  module Minato
12
12
  module Rails
@@ -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.3.0'
7
7
  end
8
8
  end
9
9
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = 'Minato Rails Auth'
12
12
  spec.description = 'Library to create an authentication layer in Rails applications'
13
13
  spec.homepage = 'https://gitlab.com/ferreri/minato/minato-rails-auth'
14
- spec.required_ruby_version = '>= 2.7'
14
+ spec.required_ruby_version = '>= 3.2'
15
15
 
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = spec.homepage
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_dependency 'activesupport', '~> 7.0.4'
32
+ spec.add_dependency 'activesupport', '~> 8.0.0'
33
33
  spec.add_dependency 'jwt', '~> 2.9'
34
34
 
35
35
  # Uncomment to register a new dependency of your gem
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferreri
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-31 00:00:00.000000000 Z
11
+ date: 2025-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.4
19
+ version: 8.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.4
26
+ version: 8.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jwt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ metadata:
70
70
  source_code_uri: https://gitlab.com/ferreri/minato/minato-rails-auth
71
71
  changelog_uri: https://gitlab.com/ferreri/minato/minato-rails-auth/-/commits/main?ref_type=heads
72
72
  rubygems_mfa_required: 'true'
73
- post_install_message:
73
+ post_install_message:
74
74
  rdoc_options: []
75
75
  require_paths:
76
76
  - lib
@@ -78,15 +78,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '2.7'
81
+ version: '3.2'
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.1.6
89
- signing_key:
88
+ rubygems_version: 3.4.19
89
+ signing_key:
90
90
  specification_version: 4
91
91
  summary: Minato Rails Auth
92
92
  test_files: []