sync_attr_with_auth0 0.1.9 → 0.2.5

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
- SHA1:
3
- metadata.gz: aedcc6948282cf1dce296ad604f0cd804a9ff24b
4
- data.tar.gz: 07cb15e12ab2849fd05ea5274cfbcb4f4828b378
2
+ SHA256:
3
+ metadata.gz: c2441467a77240b5be6d8fe7f33dfa57b5b3521945606c47803f928124b3b70f
4
+ data.tar.gz: 0231f6a6f5864485447a81c3c7e2c9e49beeb3d8def264e23f3a2cf5d863e7d6
5
5
  SHA512:
6
- metadata.gz: 2830aaa236835e9f1e0222df41af6730cf53c3c2d8286b28fd1ce097e1648e437a1bd99d51728c5f8d3ce58901fea343f6db9a830b9d6fe168c724c85fd879ef
7
- data.tar.gz: 185033676a75cd961d12d5f951072da2352541689a109e0b93622059bd4ca670a64ac026d395c40595e6c3f2d5d1bf1cb0717685981563d06e5c5e5100125d5f
6
+ metadata.gz: 15b3328e06d33cc34c39e4367b41ebfb13475679c3f9c4137c9a996b6a450396bfef27921b5ae7c29780af36cceeb92612a706e63f7043a01eae8b8f00174ca4
7
+ data.tar.gz: 40381d9b91a763b6a7722ce7da08192d0008eeb0bef7329129e473a977808e0cb7538df22ed061945e67ff5dc207cec5572c2c473f33e01484ed1f2e634f8d93
@@ -13,6 +13,7 @@ module SyncAttrWithAuth0
13
13
 
14
14
  module ClassMethods
15
15
 
16
+ # TODO: We should accept two arrays of fields: user_metadata (for user-managed settings) and app_metadata (for app-managed settings)
16
17
  def sync_attr_with_auth0(*fields)
17
18
  options = fields.extract_options!
18
19
 
@@ -159,12 +160,8 @@ module SyncAttrWithAuth0
159
160
 
160
161
 
161
162
  def auth0_app_metadata
162
- return {
163
- 'name' => auth0_user_name,
164
- 'nickname' => auth0_user_name,
165
- 'given_name' => auth0_user_given_name,
166
- 'family_name' => auth0_user_family_name
167
- }
163
+ # TODO: Source this from a separate attribute list.
164
+ return {}
168
165
  end # auth0_app_metadata
169
166
 
170
167
 
@@ -105,10 +105,8 @@ module SyncAttrWithAuth0
105
105
  def update_in_auth0(user_uid)
106
106
  return unless user_uid
107
107
 
108
- params = auth0_update_params
109
-
110
108
  begin
111
- response = SyncAttrWithAuth0::Auth0.patch_user(user_uid, params, config: auth0_sync_configuration)
109
+ response = SyncAttrWithAuth0::Auth0.patch_user(user_uid, auth0_update_params(user_uid), config: auth0_sync_configuration)
112
110
 
113
111
  # Update the record with the uid after_commit (in case it doesn't match what's on file).
114
112
  @auth0_uid = user_uid
@@ -125,7 +123,7 @@ module SyncAttrWithAuth0
125
123
  else
126
124
  # The uid was incorrect, so re-attempt with the new uid
127
125
  # and update the one on file.
128
- response = SyncAttrWithAuth0::Auth0.patch_user(found_user['user_id'], params, config: auth0_sync_configuration)
126
+ response = SyncAttrWithAuth0::Auth0.patch_user(found_user['user_id'], auth0_update_params(found_user['user_id']), config: auth0_sync_configuration)
129
127
 
130
128
  # Update the record with the uid after_commit
131
129
  @auth0_uid = found_user['user_id']
@@ -159,6 +157,10 @@ module SyncAttrWithAuth0
159
157
  'password' => password,
160
158
  'connection' => auth0_sync_configuration.connection_name,
161
159
  'email_verified' => email_verified,
160
+ 'name' => auth0_user_name,
161
+ 'nickname' => auth0_user_name,
162
+ 'given_name' => auth0_user_given_name,
163
+ 'family_name' => auth0_user_family_name,
162
164
  'user_metadata' => user_metadata,
163
165
  'app_metadata' => app_metadata
164
166
  }
@@ -167,15 +169,24 @@ module SyncAttrWithAuth0
167
169
  end # auth0_create_params
168
170
 
169
171
 
170
- def auth0_update_params
172
+ def auth0_update_params(user_uid)
171
173
  user_metadata = auth0_user_metadata
172
174
  app_metadata = auth0_app_metadata
175
+ is_auth0_connection_strategy = user_uid.start_with?("auth0|")
173
176
 
174
177
  params = {
175
178
  'app_metadata' => app_metadata,
176
179
  'user_metadata' => user_metadata
177
180
  }
178
181
 
182
+ if is_auth0_connection_strategy
183
+ # We can update the name attributes on Auth0 connection strategy only.
184
+ params['name'] = auth0_user_name
185
+ params['nickname'] = auth0_user_name
186
+ params['given_name'] = auth0_user_given_name
187
+ params['family_name'] = auth0_user_family_name
188
+ end
189
+
179
190
  if auth0_user_saved_change_to_password?
180
191
  # The password needs to be updated.
181
192
  params['password'] = auth0_user_password
@@ -14,7 +14,7 @@ module SyncAttrWithAuth0
14
14
  }
15
15
  },
16
16
  'iat' => Time.now.to_i,
17
- 'jti' => UUIDTools::UUID.timestamp_create.to_s
17
+ 'jti' => UUIDTools::UUID.random_create.to_s
18
18
  }
19
19
 
20
20
  jwt = JWT.encode(payload, JWT.base64url_decode(global_client_secret))
@@ -68,7 +68,15 @@ module SyncAttrWithAuth0
68
68
  auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client(config: config)
69
69
 
70
70
  # Use the Lucene search because Find by Email is case sensitive
71
- results = auth0.get('/api/v2/users', q: "email:#{email}")
71
+ query = "email:#{email}"
72
+ unless config.search_connections.empty?
73
+ conn_query = config.search_connections
74
+ .collect { |conn| %Q{identities.connection:"#{conn}"} }
75
+ .join ' OR '
76
+ query = "#{query} AND (#{conn_query})"
77
+ end
78
+
79
+ results = auth0.get('/api/v2/users', q: query, search_engine: 'v3')
72
80
 
73
81
  if exclude_user_id
74
82
  results = results.reject { |r| r['user_id'] == exclude_user_id }
@@ -32,7 +32,7 @@ module SyncAttrWithAuth0
32
32
  :auth0_uid_attribute, :name_attribute, :given_name_attribute,
33
33
  :family_name_attribute, :email_attribute, :password_attribute,
34
34
  :email_verified_attribute, :verify_password_attribute, :picture_attribute,
35
- :connection_name
35
+ :connection_name, :search_connections
36
36
 
37
37
 
38
38
  def initialize
@@ -52,6 +52,7 @@ module SyncAttrWithAuth0
52
52
  @verify_password_attribute = :verify_password
53
53
  @picture_attribute = :picture
54
54
  @connection_name = 'Username-Password-Authentication'
55
+ @search_connections = []
55
56
  end
56
57
  end
57
58
  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.1.9
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McGraw
@@ -169,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.6.13
172
+ rubygems_version: 3.1.2
174
173
  signing_key:
175
174
  specification_version: 4
176
175
  summary: Synchronize attributes on a local ActiveRecord user model with the user metadata