sync_attr_with_auth0 0.0.11 → 0.0.12
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 +4 -4
- data/lib/sync_attr_with_auth0/auth0.rb +18 -9
- data/lib/sync_attr_with_auth0/model.rb +17 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d8982d94b630ff6bb220ab5e1d72a28bbe6a3f4
|
4
|
+
data.tar.gz: be7794ac85d58eb8df17ce7bef35257f505da1aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea25ad9e3584c40f1de4e23926901e72590d3d9d255b9ad7044115703d2f1f8005cd4b535f7dd421dfbd3480faab26b3b1cd3fd19b55005edab61cf6cf6b31fd
|
7
|
+
data.tar.gz: 5a01564f7969124e06608bf258bbaaa9d83f28cf83e22e5a68e0a33fb39f2ac09bdf679458775f30e684e02d65ac1decb56faaca3c98ad5c6e560116a76de9e5
|
@@ -3,9 +3,9 @@ module SyncAttrWithAuth0
|
|
3
3
|
require "auth0"
|
4
4
|
require "uuidtools"
|
5
5
|
|
6
|
-
def self.create_auth0_jwt
|
6
|
+
def self.create_auth0_jwt(global_client_id: ENV['AUTH0_GLOBAL_CLIENT_ID'], global_client_secret: ENV['AUTH0_GLOBAL_CLIENT_SECRET'])
|
7
7
|
payload = {
|
8
|
-
'aud' =>
|
8
|
+
'aud' => global_client_id,
|
9
9
|
'scopes' => {
|
10
10
|
'users' => {
|
11
11
|
'actions' => ['create', 'update', 'read']
|
@@ -15,17 +15,26 @@ module SyncAttrWithAuth0
|
|
15
15
|
'jti' => UUIDTools::UUID.timestamp_create.to_s
|
16
16
|
}
|
17
17
|
|
18
|
-
jwt = JWT.encode(payload,
|
18
|
+
jwt = JWT.encode(payload, JWT.base64url_decode(global_client_secret))
|
19
19
|
|
20
20
|
return jwt
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.create_auth0_client
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def self.create_auth0_client(
|
24
|
+
api_version: 2,
|
25
|
+
global_client_id: ENV['AUTH0_GLOBAL_CLIENT_ID'],
|
26
|
+
global_client_secret: ENV['AUTH0_GLOBAL_CLIENT_SECRET'],
|
27
|
+
client_id: ENV['AUTH0_CLIENT_ID'],
|
28
|
+
client_secret: ENV['AUTH0_CLIENT_SECRET']
|
29
|
+
namespace: ENV['AUTH0_DOMAIN']
|
30
|
+
)
|
31
|
+
case api_version
|
32
|
+
when 1
|
33
|
+
auth0 = Auth0Client.new(client_id: client_id, client_secret: client_secret, namespace: namespace)
|
34
|
+
when 2
|
35
|
+
jwt = SyncAttrWithAuth0::Auth0.create_auth0_jwt
|
36
|
+
auth0 = Auth0Client.new(api_version: 2, access_token: jwt, namespace: namespace)
|
37
|
+
end
|
29
38
|
|
30
39
|
return auth0
|
31
40
|
end
|
@@ -48,8 +48,6 @@ module SyncAttrWithAuth0
|
|
48
48
|
}
|
49
49
|
|
50
50
|
self.auth0_sync_options.merge!(options)
|
51
|
-
|
52
|
-
return _options
|
53
51
|
end
|
54
52
|
|
55
53
|
end
|
@@ -61,18 +59,20 @@ module SyncAttrWithAuth0
|
|
61
59
|
ok_to_validate = (self.respond_to?(:validate_with_auth0) and !self.validate_with_auth0.nil? ? self.validate_with_auth0 : true)
|
62
60
|
|
63
61
|
if ok_to_validate and self.email_changed?
|
64
|
-
auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
|
62
|
+
auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client(api_version: 1)
|
65
63
|
|
66
|
-
response = auth0.users(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
64
|
+
response = auth0.users("email:#{self.send(auth0_sync_options[:email_att])}")
|
65
|
+
|
66
|
+
# response = auth0.users(
|
67
|
+
# 1,
|
68
|
+
# 0,
|
69
|
+
# nil,
|
70
|
+
# nil,
|
71
|
+
# auth0_sync_options[:connection_name],
|
72
|
+
# nil,
|
73
|
+
# nil,
|
74
|
+
# "email:#{self.send(auth0_sync_options[:email_att])}"
|
75
|
+
# )
|
76
76
|
|
77
77
|
return JSON.parse(response).empty?
|
78
78
|
end
|
@@ -157,13 +157,14 @@ module SyncAttrWithAuth0
|
|
157
157
|
auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
|
158
158
|
|
159
159
|
args = {
|
160
|
+
# 'email' => self.send(auth0_sync_options[:email_att]),
|
161
|
+
# 'password' => auth0_user_password, Don't want to reset the user's password every edit.
|
162
|
+
|
160
163
|
'app_metadata' => {
|
161
164
|
'name' => self.send(auth0_sync_options[:name_att]),
|
162
165
|
'nickname' => self.send(auth0_sync_options[:name_att]),
|
163
166
|
'given_name' => self.send(auth0_sync_options[:given_name_att]),
|
164
|
-
'family_name' => self.send(auth0_sync_options[:family_name_att])
|
165
|
-
'email' => self.send(auth0_sync_options[:email_att]),
|
166
|
-
'password' => self.send(auth0_sync_options[:password_att])
|
167
|
+
'family_name' => self.send(auth0_sync_options[:family_name_att])
|
167
168
|
}
|
168
169
|
}
|
169
170
|
|