sync_attr_with_auth0 0.0.12 → 0.0.13

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: 5d8982d94b630ff6bb220ab5e1d72a28bbe6a3f4
4
- data.tar.gz: be7794ac85d58eb8df17ce7bef35257f505da1aa
3
+ metadata.gz: ad39e17ebaa360e7b5755a13cf8accf7843abba3
4
+ data.tar.gz: 9037b53718a5a4ddd22da02266a438645cb7ef2a
5
5
  SHA512:
6
- metadata.gz: ea25ad9e3584c40f1de4e23926901e72590d3d9d255b9ad7044115703d2f1f8005cd4b535f7dd421dfbd3480faab26b3b1cd3fd19b55005edab61cf6cf6b31fd
7
- data.tar.gz: 5a01564f7969124e06608bf258bbaaa9d83f28cf83e22e5a68e0a33fb39f2ac09bdf679458775f30e684e02d65ac1decb56faaca3c98ad5c6e560116a76de9e5
6
+ metadata.gz: f038ebbd02435ba03edb40c0d09fa03b7c80c4367c65d2c4fc3a5f3a91dc0e005c8b443ad3ad317ff23c206489a3a04a5dfcba8f0200bd96f97107a38aff53a9
7
+ data.tar.gz: d8a3a29eb4f664d1888413aea263946f06e2c62c1a3de7db2087da316bb963b019f1a447a2538a8e9e4b66f8639a778f9078c16fff12f49107626c1aada4e7d1
@@ -25,56 +25,19 @@ module SyncAttrWithAuth0
25
25
  global_client_id: ENV['AUTH0_GLOBAL_CLIENT_ID'],
26
26
  global_client_secret: ENV['AUTH0_GLOBAL_CLIENT_SECRET'],
27
27
  client_id: ENV['AUTH0_CLIENT_ID'],
28
- client_secret: ENV['AUTH0_CLIENT_SECRET']
28
+ client_secret: ENV['AUTH0_CLIENT_SECRET'],
29
29
  namespace: ENV['AUTH0_DOMAIN']
30
30
  )
31
31
  case api_version
32
32
  when 1
33
33
  auth0 = Auth0Client.new(client_id: client_id, client_secret: client_secret, namespace: namespace)
34
34
  when 2
35
- jwt = SyncAttrWithAuth0::Auth0.create_auth0_jwt
35
+ jwt = SyncAttrWithAuth0::Auth0.create_auth0_jwt(global_client_id: global_client_id, global_client_secret: global_client_secret)
36
36
  auth0 = Auth0Client.new(api_version: 2, access_token: jwt, namespace: namespace)
37
37
  end
38
38
 
39
39
  return auth0
40
40
  end
41
41
 
42
- ###
43
- # This stuff is legacy now. It's probably best to remove this stuff once the
44
- # auth0 API stuff is working.
45
- ###
46
- # def self.get_access_token
47
- # payload = {
48
- # "client_id" => ENV['AUTH0_CLIENT_ID'],
49
- # "client_secret" => ENV['AUTH0_CLIENT_SECRET'],
50
- # "grant_type" => "client_credentials"
51
- # }
52
- #
53
- # response = SyncAttrWithAuth0::Auth0.make_request(nil, 'post', '/oauth/token', payload)
54
- #
55
- # response = JSON.parse( response.to_s ) unless response.nil? or response.to_s.empty?
56
- #
57
- # response['access_token']
58
- # end
59
- #
60
- # def self.make_request(access_token, method, path, payload=nil)
61
- # args = [method, "https://#{ENV['AUTH0_DOMAIN']}#{path}"]
62
- #
63
- # # The post body wedges in between the request url
64
- # # and the request headers for POST and PUT methods
65
- # args << payload if payload
66
- #
67
- # if access_token
68
- # args << { content_type: :json, authorization: "Bearer #{access_token}", accept: "application/json" }
69
- #
70
- # else
71
- # args << { content_type: :json, accept: "application/json" }
72
- #
73
- # end
74
- #
75
- # # Handle variable length arg lists
76
- # _response = RestClient.send(*args)
77
- # end
78
-
79
42
  end
80
43
  end
@@ -9,24 +9,8 @@ module SyncAttrWithAuth0
9
9
  def sync_attr_with_auth0(options = {})
10
10
  class_attribute :auth0_sync_options
11
11
 
12
- # class_attribute :auth0_uid_att
13
- # class_attribute :auth0_name_att
14
- # class_attribute :auth0_email_att
15
- # class_attribute :auth0_password_att
16
- # class_attribute :auth0_email_verified_att
17
- # class_attribute :auth0_connection_name
18
- # class_attribute :auth0_sync_atts
19
-
20
12
  merge_default_options(options)
21
13
 
22
- # self.auth0_uid_att = _options[:uid_att]
23
- # self.auth0_name_att = _options[:name_att]
24
- # self.auth0_email_att = _options[:email_att]
25
- # self.auth0_password_att = _options[:password_att]
26
- # self.auth0_email_verified_att = _options[:auth0_email_verified_att]
27
- # self.auth0_connection_name = _options[:auth0_connection_name]
28
- # self.auth0_sync_atts = _options[:auth0_sync_atts].collect(&:to_s)
29
-
30
14
  after_validation :validate_email_with_auth0
31
15
  after_create :create_user_in_auth0
32
16
  after_update :sync_attr_with_auth0
@@ -39,7 +23,7 @@ module SyncAttrWithAuth0
39
23
  uid_att: :uid,
40
24
  name_att: :name,
41
25
  given_name_att: :given_name,
42
- family_name_att: :familiy_name,
26
+ family_name_att: :family_name,
43
27
  email_att: :email,
44
28
  password_att: :password,
45
29
  email_verified_att: :email_verified,
@@ -63,18 +47,7 @@ module SyncAttrWithAuth0
63
47
 
64
48
  response = auth0.users("email:#{self.send(auth0_sync_options[:email_att])}")
65
49
 
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
-
77
- return JSON.parse(response).empty?
50
+ return response.empty?
78
51
  end
79
52
 
80
53
  return true
@@ -93,28 +66,8 @@ module SyncAttrWithAuth0
93
66
  end
94
67
 
95
68
  if ok_to_sync
96
- # # Look for matches between what's changing
97
- # # and what needs to be transmitted to Auth0
98
- # matches = ( (self.class.auth0_sync_options[:sync_atts] || []) & (self.changes.keys || []) )
99
- #
100
- # # Figure out what needs to be sent to Auth0
101
- # changes = {}
102
- # matches.each do |m|
103
- # changes[m] = self.send(m) if self.respond_to?(m)
104
- # end
105
-
106
69
  user_metadata = auth0_user_metadata
107
70
 
108
- # unless user_metadata['email'].nil?
109
- # # Email is already being sent
110
- # user_metadata.delete('email')
111
- # end
112
- #
113
- # unless user_metadata['password'].nil?
114
- # # Password is already being sent
115
- # user_metadata.delete('password')
116
- # end
117
-
118
71
  password = auth0_user_password
119
72
  email_verified = auth0_email_verified?
120
73
  args = {
@@ -129,8 +82,6 @@ module SyncAttrWithAuth0
129
82
 
130
83
  response = auth0.create_user(self.send(auth0_sync_options[:name_att]), args)
131
84
 
132
- response = JSON.parse(response)
133
-
134
85
  # Update the record with the uid
135
86
  self.send("#{auth0_sync_options[:uid_att]}=", response['user_id'])
136
87
  self.save
@@ -143,9 +94,6 @@ module SyncAttrWithAuth0
143
94
  ok_to_sync = (self.respond_to?(:sync_with_auth0_on_update) and !self.sync_with_auth0_on_update.nil? ? self.sync_with_auth0_on_update : true)
144
95
 
145
96
  if ok_to_sync
146
- # # Look for matches between what's changing
147
- # # and what needs to be transmitted to Auth0
148
- # matches = ( (self.class.auth0_sync_options[:sync_atts] || []) & (self.changes.keys || []) )
149
97
 
150
98
  # Get the auth0 uid
151
99
  uid = self.send(auth0_sync_options[:uid_att])
@@ -157,9 +105,6 @@ module SyncAttrWithAuth0
157
105
  auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
158
106
 
159
107
  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
-
163
108
  'app_metadata' => {
164
109
  'name' => self.send(auth0_sync_options[:name_att]),
165
110
  'nickname' => self.send(auth0_sync_options[:name_att]),
@@ -173,47 +118,6 @@ module SyncAttrWithAuth0
173
118
  response = auth0.patch_user(uid, args)
174
119
  end
175
120
 
176
- # # If we find matches
177
- # unless matches.empty?
178
- # # Figure out what needs to be sent to Auth0
179
- # changes = {}
180
- # matches.each do |m|
181
- # changes[m] = self.send(m)
182
- # end
183
- #
184
- # # If we actually have changes
185
- # unless changes.empty?
186
- # # Get the auth0 uid
187
- # uid = self.send(auth0_sync_options[:uid_att])
188
- #
189
- # # Don't try to update auth0 if the user doesn't have a uid
190
- # unless uid.nil?
191
- # auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
192
- #
193
- # args = {
194
- # 'app_metadata' => {
195
- # 'name' => self.send(auth0_sync_options[:name_att]),
196
- # 'nickname' => self.send(auth0_sync_options[:name_att]),
197
- # 'given_name' => self.send(auth0_sync_options[:given_name_att]),
198
- # 'family_name' => self.send(auth0_sync_options[:family_name_att])
199
- # }
200
- # }
201
- # unless changes['email'].nil?
202
- # args['app_metadata']['username'] = changes.delete('email')
203
- # end
204
- #
205
- # unless changes['password'].nil?
206
- # args['app_metadata']['password'] = changes.delete('password')
207
- # end
208
- #
209
- # args['user_metadata'] = changes
210
- #
211
- # response = auth0.patch_user(uid, args)
212
- # end
213
- #
214
- # end
215
- # end
216
-
217
121
  end
218
122
 
219
123
  true # don't abort the callback chain
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.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McGraw