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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecd06b713cb0483a806cadad455b891d05675ddaf98b4b59075109739eb94be3
|
4
|
+
data.tar.gz: 45f4fdc87af07f2507acc9d8ba18cf8b67061991ecb4744232f673a92ace9fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
3
|
+
def google
|
4
4
|
callback 'Google', from_params, 'google'
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
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 => [
|
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]
|
data/lib/thecore_auth_commons.rb
CHANGED
@@ -14,9 +14,20 @@ require "thecore/seed"
|
|
14
14
|
|
15
15
|
module ThecoreAuthCommons
|
16
16
|
def self.oauth_vars?
|
17
|
-
|
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
|