sync_attr_with_auth0 0.0.8 → 0.0.9

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: 3246f32ec92050681aab8b9aa1ebcd0f7ae99c67
4
- data.tar.gz: 7c5ab7c21b67074319e8de0847ed6a184f831c05
3
+ metadata.gz: c5dbe1442a3af7681a771da1ce3485d163518894
4
+ data.tar.gz: efd544f8895ae166faf50ef9e505d506bcd5910d
5
5
  SHA512:
6
- metadata.gz: f21dde98a00d2654357bbb82bdc890ef9fc4d91c643abeed37e5be47e68b440861ca7f33045108e7a14780d586bf1ba512234d406e639023cc7b6c2fed1de9f5
7
- data.tar.gz: d8a25ca9ae6f4c21546b7a52924fd81156708e738e6ad838bff6ce0127ad12c27fea731c9ff4375d54b0967770cfe7fdb2277d517f029adabadf463f7336ae2a
6
+ metadata.gz: 94774bc790992b01714dfff959f3aa6e15e106be382adef28f8f776a8f3ff05fe28e848f0612d147b79ba4274951ab78fa785123290afe2df4a22d5b69197124
7
+ data.tar.gz: 97d1827a0db3fccfcec99b32ba1b382679ce241a210bed1620ec6eaa80943d348516763c446208de91d8f486d19fbe1dbcce084589a283955f3c2db927c7c08f
@@ -7,21 +7,21 @@ module SyncAttrWithAuth0
7
7
  module ClassMethods
8
8
 
9
9
  def sync_attr_with_auth0(options = {})
10
- class_attribute :uid_att
11
- class_attribute :email_att
12
- class_attribute :password_att
13
- class_attribute :email_verified_att
14
- class_attribute :connection_name
15
- class_attribute :sync_atts
10
+ class_attribute :auth0_uid_att
11
+ class_attribute :auth0_email_att
12
+ class_attribute :auth0_password_att
13
+ class_attribute :auth0_email_verified_att
14
+ class_attribute :auth0_connection_name
15
+ class_attribute :auth0_sync_atts
16
16
 
17
17
  _options = merge_default_options(options)
18
18
 
19
- self.uid_att = _options[:uid_att]
20
- self.email_att = _options[:email_att]
21
- self.password_att = _options[:password_att]
22
- self.email_verified_att = _options[:email_verified_att]
23
- self.connection_name = _options[:connection_name]
24
- self.sync_atts = _options[:sync_atts].collect(&:to_s)
19
+ self.auth0_uid_att = _options[:auth0_uid_att]
20
+ self.auth0_email_att = _options[:auth0_email_att]
21
+ self.auth0_password_att = _options[:auth0_password_att]
22
+ self.auth0_email_verified_att = _options[:auth0_email_verified_att]
23
+ self.auth0_connection_name = _options[:auth0_connection_name]
24
+ self.auth0_sync_atts = _options[:auth0_sync_atts].collect(&:to_s)
25
25
 
26
26
  after_validation :validate_email_with_auth0
27
27
  after_create :create_user_in_auth0
@@ -32,12 +32,12 @@ module SyncAttrWithAuth0
32
32
 
33
33
  def merge_default_options(options)
34
34
  _options = {
35
- uid_att: :uid,
36
- email_att: :email,
37
- password_att: :password,
38
- email_verified_att: :email_verified,
39
- connection_name: 'Username-Password-Authentication',
40
- sync_atts: []
35
+ auth0_uid_att: :uid,
36
+ auth0_email_att: :email,
37
+ auth0_password_att: :password,
38
+ auth0_email_verified_att: :email_verified,
39
+ auth0_connection_name: 'Username-Password-Authentication',
40
+ auth0_sync_atts: []
41
41
  }
42
42
 
43
43
  _options.merge!(options)
@@ -73,13 +73,20 @@ module SyncAttrWithAuth0
73
73
 
74
74
  ok_to_sync = (self.respond_to?(:sync_with_auth0_on_create) and !self.sync_with_auth0_on_create.nil? ? self.sync_with_auth0_on_create : true)
75
75
 
76
+ # Do not create a user in auth0 if the user already has a uid from auth0
77
+ if ok_to_sync
78
+ unless self.send(auth0_uid_att).nil? or self.send(auth0_uid_att).empty?
79
+ ok_to_sync = false
80
+ end
81
+ end
82
+
76
83
  if ok_to_sync
77
84
  # Get an access token
78
85
  access_token = SyncAttrWithAuth0::Auth0.get_access_token
79
86
 
80
87
  # Look for matches between what's changing
81
88
  # and what needs to be transmitted to Auth0
82
- matches = ( (self.class.sync_atts || []) & (self.changes.keys || []) )
89
+ matches = ( (self.class.auth0_sync_atts || []) & (self.changes.keys || []) )
83
90
 
84
91
  # Figure out what needs to be sent to Auth0
85
92
  changes = {}
@@ -100,10 +107,10 @@ module SyncAttrWithAuth0
100
107
  password = auth0_user_password
101
108
  email_verified = auth0_email_verified?
102
109
  args = {
103
- 'email' => self.send(email_att),
110
+ 'email' => self.send(auth0_email_att),
104
111
  'password' => password,
105
- 'connection' => connection_name,
106
- 'email_verified' => true #email_verified
112
+ 'connection' => auth0_connection_name,
113
+ 'email_verified' => email_verified
107
114
  }.merge(changes)
108
115
 
109
116
  response = SyncAttrWithAuth0::Auth0.make_request(
@@ -115,7 +122,7 @@ module SyncAttrWithAuth0
115
122
  response = JSON.parse(response)
116
123
 
117
124
  # Update the record with the uid
118
- self.send("#{uid_att}=", response['user_id'])
125
+ self.send("#{auth0_uid_att}=", response['user_id'])
119
126
  self.save
120
127
  end
121
128
 
@@ -128,7 +135,7 @@ module SyncAttrWithAuth0
128
135
  if ok_to_sync
129
136
  # Look for matches between what's changing
130
137
  # and what needs to be transmitted to Auth0
131
- matches = ( (self.class.sync_atts || []) & (self.changes.keys || []) )
138
+ matches = ( (self.class.auth0_sync_atts || []) & (self.changes.keys || []) )
132
139
 
133
140
  # If we find matches
134
141
  unless matches.empty?
@@ -145,7 +152,7 @@ module SyncAttrWithAuth0
145
152
  # If we actually have changes
146
153
  unless changes.empty?
147
154
  # Get the auth0 uid
148
- uid = self.send(uid_att)
155
+ uid = self.send(auth0_uid_att)
149
156
 
150
157
  # Don't try to update auth0 if the user doesn't have a uid
151
158
  unless uid.nil?
@@ -165,7 +172,7 @@ module SyncAttrWithAuth0
165
172
  response = JSON.parse(response)
166
173
 
167
174
  # Update the record with the uid
168
- self.send("#{uid_att}=", response['user_id'])
175
+ self.send("#{auth0_uid_att}=", response['user_id'])
169
176
  self.save
170
177
  end
171
178
 
@@ -200,11 +207,11 @@ module SyncAttrWithAuth0
200
207
  end
201
208
 
202
209
  def auth0_user_password
203
- self.respond_to?(password_att) ? self.send(password_att) : auth0_default_password
210
+ self.respond_to?(auth0_password_att) ? self.send(auth0_password_att) : auth0_default_password
204
211
  end
205
212
 
206
213
  def auth0_email_verified?
207
- !!(self.respond_to?(email_verified_att) ? self.send(email_verified_att) : false)
214
+ !!(self.respond_to?(auth0_email_verified_att) ? self.send(auth0_email_verified_att) : false)
208
215
  end
209
216
 
210
217
  def auth0_default_password
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McGraw