sync_attr_with_auth0 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 150f4f03236db891bc4d1282f1f80ebedbe40799
4
- data.tar.gz: 8472efd778006cd84e1c49cef5e70a6ac03b5229
3
+ metadata.gz: 0fb1101e092bccf7062ac9ca3a6f02e351c94ef5
4
+ data.tar.gz: d12bca90a91da479fa0834d320a2742afbe0259f
5
5
  SHA512:
6
- metadata.gz: 615714c6687b570fe7d11b3ff45a7ed75f12d128dc93567f5c0697dc8c030f6d9ebb5b19eca47f51ea0e65b7f1dad4de1d792ad07dd754b25d3d9935ddcaa1b6
7
- data.tar.gz: 6048ab73ee2eb08455ec72d5f2da74ff9766bab860bb99197c63c1d08efbbee4ff0685af739e08bb66ee133f5c18f9add09630d5f11191983cd4c3b790d11693
6
+ metadata.gz: ce1e10fbb37dfaf2371dbb9931485ac13ce85d4dbf496978de9d5345100c23f24d16782f6e82a92847d67a183613cfdaef3c0562b93c6af71e329b57e977abe9
7
+ data.tar.gz: d00fdd4c41d1235fe2ea36207cb3527e5c9c47face0872c8431af2b89ebadb7a17412ba9e3136484d5ec7e289137f180885437d7e642500024563dca3391f75e
@@ -60,9 +60,7 @@ module SyncAttrWithAuth0
60
60
  ok_to_validate = (self.respond_to?(:validate_with_auth0) and !self.validate_with_auth0.nil? ? self.validate_with_auth0 : true)
61
61
 
62
62
  if ok_to_validate and self.email_changed?
63
- auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client(api_version: 1)
64
-
65
- response = auth0.users("email:#{self.send(auth0_sync_options[:email_att])}")
63
+ response = find_user_in_auth0
66
64
 
67
65
  return response.empty?
68
66
  end
@@ -100,7 +98,7 @@ module SyncAttrWithAuth0
100
98
  # TODO: create a user if the uid is nil
101
99
  unless uid.nil?
102
100
  # Update the user in auth0
103
- update_user_in_auth0
101
+ update_user_in_auth0(uid)
104
102
  end
105
103
 
106
104
  end
@@ -108,10 +106,15 @@ module SyncAttrWithAuth0
108
106
  true # don't abort the callback chain
109
107
  end
110
108
 
111
- def create_user_in_auth0
109
+ def create_user_in_auth0()
112
110
  user_metadata = auth0_user_metadata
113
111
 
114
112
  password = auth0_user_password
113
+
114
+ if password.nil?
115
+ password = auth0_default_password
116
+ end
117
+
115
118
  email_verified = auth0_email_verified?
116
119
  args = {
117
120
  'email' => self.send(auth0_sync_options[:email_att]),
@@ -130,7 +133,7 @@ module SyncAttrWithAuth0
130
133
  self.save
131
134
  end
132
135
 
133
- def update_user_in_auth0
136
+ def update_user_in_auth0(uid)
134
137
  user_metadata = auth0_user_metadata
135
138
 
136
139
  auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
@@ -161,10 +164,24 @@ module SyncAttrWithAuth0
161
164
  args['user_metadata'] = user_metadata
162
165
 
163
166
  begin
164
- response = auth0.patch_user(uid, args)
167
+ auth0.patch_user(uid, args)
165
168
 
166
169
  rescue ::Auth0::NotFound => e
167
170
  # TODO: We need to attempt to find the correct UID by email or nil the UID on the user.
171
+ response = find_user_in_auth0
172
+ found_user = response.first
173
+
174
+ if found_user.nil?
175
+ # Could not find the user, create it in auth0
176
+ create_user_in_auth0
177
+ else
178
+ # Update with the new uid and correct the one on file
179
+ auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
180
+ auth0.patch_user(found_user['user_id'], args)
181
+
182
+ self.send("#{auth0_sync_options[:uid_att]}=", found_user['user_id'])
183
+ self.save
184
+ end
168
185
 
169
186
  rescue Exception => e
170
187
  ::Rails.logger.error e.message
@@ -174,6 +191,14 @@ module SyncAttrWithAuth0
174
191
  end
175
192
  end
176
193
 
194
+ def find_user_in_auth0
195
+ auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client(api_version: 1)
196
+
197
+ response = auth0.users("email:#{self.send(auth0_sync_options[:email_att])}")
198
+
199
+ return response
200
+ end
201
+
177
202
  def auth0_user_password
178
203
  self.respond_to?(auth0_sync_options[:password_att]) ? self.send(auth0_sync_options[:password_att]) : auth0_default_password
179
204
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_attr_with_auth0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McGraw