thecore_auth_commons 3.5.2 → 3.5.4

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: 29a083c2300c45d950b99efa4ff7e8a5642c11212acd01d392bb07f63fb38a19
4
- data.tar.gz: 9a20546917d55959cf5aa5d4c272c43e7f09efc5888d80d05d9edbb634b499f8
3
+ metadata.gz: ecd06b713cb0483a806cadad455b891d05675ddaf98b4b59075109739eb94be3
4
+ data.tar.gz: 45f4fdc87af07f2507acc9d8ba18cf8b67061991ecb4744232f673a92ace9fa2
5
5
  SHA512:
6
- metadata.gz: dbf9f9bcc726736caf0b785807609235d98b56f2180e9b9bd1af32b1167333c739ab27d6992a038b33d8a859612ce09bb6474f9f9851c5f4f0aa6bb74ebb702b
7
- data.tar.gz: edf61e953a0cc68f0d9bde2866499e609241519f9511397cb6730e6549d560cfebbdb2a395ec0f61020c8ca0e8a2089b0c7f4dfe6e59e4dec92629ade6066b67
6
+ metadata.gz: 529ccf61e8caa44fa603f8b3ee2c45299552e351ed6debb355b8dd4acbccf9673b7f40f119ca349a71bd7360c9debbfefc0c1975a0e272f548461fb842064a24
7
+ data.tar.gz: 34d5f3591ce355d0af8b65d00c60db3250c04ca9ca1b39ed4d8faada6bfd56e945a028570f78988d6c817c411b1138de8e6b47146f61f4f6ca6ac42783757770
@@ -1,10 +1,10 @@
1
1
  # app/controllers/users/omniauth_callbacks_controller.rb
2
2
  class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
3
- def google_oauth2
3
+ def google
4
4
  callback 'Google', from_params, 'google'
5
5
  end
6
6
 
7
- def entra_id
7
+ def microsoft
8
8
  callback 'Microsoft Entra ID', from_params, 'entra_id'
9
9
  end
10
10
 
data/app/models/user.rb CHANGED
@@ -8,7 +8,10 @@ class User < ApplicationRecord
8
8
  :validatable,
9
9
  # Devise modules configurations:
10
10
  # Omniauthable allows the user to sign in with external providers
11
- :omniauth_providers => [:google_oauth2, :entra_id],
11
+ :omniauth_providers => [
12
+ ThecoreAuthCommons.entra_id_vars? && 'microsoft',
13
+ ThecoreAuthCommons.google_oauth2_vars? && 'google'
14
+ ].select(&:itself).compact,
12
15
  # Validatable allows the user to validate their email and password
13
16
  :password_length => ENV.fetch('MIN_PASSWORD_LENGTH', 8).to_i..128,
14
17
  :timeout_in => ENV.fetch('SESSION_TIMEOUT_IN_MINUTES', 31).to_i.minutes
@@ -8,12 +8,10 @@ Rails.application.config.middleware.use OmniAuth::Builder do
8
8
  client_secret: ENV['ENTRA_CLIENT_SECRET'],
9
9
  tenant_id: ENV['ENTRA_TENANT_ID'], # Needed for Microsoft
10
10
  scope: 'openid profile email User.Read',
11
- response_type: 'code'
12
- },
13
- {
14
- label: "Microsoft"
11
+ response_type: 'code',
12
+ name: "microsoft"
15
13
  }
16
- )
14
+ ) if ThecoreAuthCommons.entra_id_vars?
17
15
  provider(
18
16
  :google_oauth2,
19
17
  ENV['GOOGLE_CLIENT_ID'],
@@ -21,9 +19,10 @@ Rails.application.config.middleware.use OmniAuth::Builder do
21
19
  {
22
20
  scope: 'email,profile',
23
21
  prompt: 'select_account',
24
- access_type: 'online'
22
+ access_type: 'online',
23
+ name: "google"
25
24
  }
26
- )
25
+ ) if ThecoreAuthCommons.google_oauth2_vars?
27
26
  end
28
27
 
29
28
  OmniAuth.config.allowed_request_methods = [:get, :post]
@@ -1,3 +1,3 @@
1
1
  module ThecoreAuthCommons
2
- VERSION = "3.5.2".freeze
2
+ VERSION = "3.5.4".freeze
3
3
  end
@@ -14,9 +14,20 @@ require "thecore/seed"
14
14
 
15
15
  module ThecoreAuthCommons
16
16
  def self.oauth_vars?
17
- (ENV['ENTRA_CLIENT_ID'].present? && ENV['ENTRA_CLIENT_SECRET'].present? && ENV['ENTRA_TENANT_ID'].present?) || (ENV['GOOGLE_CLIENT_ID'].present? && ENV['GOOGLE_CLIENT_SECRET'].present?)
17
+ entra_id_vars? || google_oauth2_vars?
18
18
  end
19
19
 
20
+ def self.entra_id_vars?
21
+ ENV['ENTRA_CLIENT_ID'].present? && ENV['ENTRA_CLIENT_SECRET'].present? && ENV['ENTRA_TENANT_ID'].present?
22
+ end
23
+
24
+ def self.google_oauth2_vars?
25
+ ENV['GOOGLE_CLIENT_ID'].present? && ENV['GOOGLE_CLIENT_SECRET'].present?
26
+ end
27
+
28
+ # Controlla se l'utente esiste, altrimenti lo crea con una password casuale
29
+ # e lo restituisce. Se l'utente esiste già, lo restituisce senza modificarlo.
30
+
20
31
  def self.check_user email, name, surname, provider
21
32
  u = User.find_or_initialize_by(email: email)
22
33
  u.name = name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_auth_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.2
4
+ version: 3.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni