Skip to content

Commit bd4c082

Browse files
committed
0.8.2
1 parent 6cd21b1 commit bd4c082

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rules-templates",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "Auth0 Rules Repository",
55
"main": "./rules",
66
"scripts": {

rules.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@
278278
"code": "function (user, context, callback) {\n if (context.connection !== 'linkedin') {\n return callback(null, user, context);\n }\n\n const request = require('request');\n\n const liIdentity = _.find(user.identities, { connection: 'linkedin' });\n\n const options = {\n url: 'https://api.linkedin.com/v1/people/~/picture-urls::(original)?format=json',\n headers: {\n Authorization: 'Bearer ' + liIdentity.access_token\n },\n json: true\n };\n\n request(options, function (error, response, body) {\n if (error) return callback(error);\n if (response.statusCode !== 200) return callback(new Error(body));\n\n if (body.values && body.values.length >= 1) {\n context.idToken.picture = body.values[0];\n }\n\n return callback(null, user, context);\n });\n}"
279279
},
280280
{
281-
"id": "migrate_root_attributes",
281+
"id": "migrate-root-attributes",
282282
"title": "Move user_metadata attributes to profile root attributes.",
283283
"overview": "Moves select data from user_metadata to profile root attributes (family_name, given_name, name, nickname and picture).",
284284
"categories": [
285285
"enrich profile"
286286
],
287-
"description": "<p>This rule moves select data from user<em>metadata to profile root attributes (family</em>name, given<em>name, name, nickname and picture).\nVerify the field mapping before enabling this rule.\nThe rule will determine if there is a mapped field on the user</em>metadata before the update.\nImportant:</p>\n<p>1- The rule updates the profile root attribute with the mapped field from user<em>metadata.\n2- The mapped fields from user</em>metadata will be removed following the update.\n3- This rule will be executed on each login event. Consider using it only if you use a custom signup form or Authentication Signup API.</p>",
288-
"code": "function (user, context, cb) {\n // Field Mapping, the property is the root attribute and the value is the field name on user_metadata.\n // You can change the value in case you don't have the same name on user_metadata.\n const fieldMapping = {\n family_name: 'family_name',\n given_name: 'given_name',\n name: 'name',\n nickname: 'nickname',\n picture: 'picture'\n };\n\n if (needMigration(user)) {\n const ManagementClient = require('[email protected]').ManagementClient;\n const management = new ManagementClient({\n domain: auth0.domain,\n token: auth0.accessToken\n });\n\n management.updateUser(\n { id: user.user_id }, generateUserPayload(user), function (err, updatedUser) {\n if ( err ) {\n cb(err);\n } else {\n updateRuleUser(user, updatedUser);\n cb(null, user, context);\n }\n }\n );\n } else {\n cb(null, user, context);\n }\n\n function needMigration(user) {\n if (user.user_metadata) {\n for (const key in fieldMapping) {\n if (user.user_metadata[key]) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n function generateUserPayload(user) {\n const payload = { user_metadata: {}};\n const userMetadata = user.user_metadata;\n\n for (const key in fieldMapping) {\n generateUserPayloadField(userMetadata, payload, key, fieldMapping[key]);\n }\n\n return payload;\n }\n\n function updateRuleUser(user, updatedUser) {\n for (const key in fieldMapping) {\n const updatedUserField = updatedUser[fieldMapping[key]];\n if (typeof updatedUserField === 'string') {\n user[fieldMapping[key]] = updatedUserField;\n user.user_metadata[fieldMapping[key]] = null;\n }\n }\n }\n\n function generateUserPayloadField(userMetadata, payload, rootField, metadataField) {\n if (typeof userMetadata[metadataField] === 'string') {\n payload[rootField] = userMetadata[metadataField];\n payload.user_metadata[metadataField] = null;\n }\n }\n}"
287+
"description": "<p>This rule moves select data from user<em>metadata to profile root attributes (family</em>name, given<em>name, name, nickname and picture).\nVerify the field mapping before enabling this rule.\nThe rule will determine if there is a mapped field on the user</em>metadata before the update.\nImportant:</p>\n<p>1- The rule updates the profile root attribute with the mapped field from user<em>metadata.\n2- The mapped fields from user</em>metadata will be removed following the update.\n3- This rule will be executed on each login event. For signup scenarios, you should only consider using this rule if you currently use a custom signup form or Authentication Signup API, as these signup methods do not support setting the root attributes.</p>",
288+
"code": "function (user, context, cb) {\n // Field Mapping, the property is the root attribute and the value is the field name on user_metadata.\n // You can change the value in case you don't have the same name on user_metadata.\n var fieldMapping = {\n family_name: 'family_name',\n given_name: 'given_name',\n name: 'name',\n nickname: 'nickname',\n picture: 'picture'\n };\n\n if (needMigration(user)) {\n var ManagementClient = require('[email protected]').ManagementClient;\n var management = new ManagementClient({\n domain: auth0.domain,\n token: auth0.accessToken\n });\n\n management.updateUser(\n { id: user.user_id }, generateUserPayload(user), function (err, updatedUser) {\n if ( err ) {\n cb(err);\n } else {\n updateRuleUser(user, updatedUser);\n cb(null, user, context);\n }\n }\n );\n } else {\n cb(null, user, context);\n }\n\n function needMigration(user) {\n if (user.user_metadata) {\n for (var key in fieldMapping) {\n if (typeof user.user_metadata[fieldMapping[key]] === 'string') {\n return true;\n }\n }\n }\n\n return false;\n }\n\n function generateUserPayload(user) {\n var payload = { user_metadata: {}};\n var userMetadata = user.user_metadata;\n\n for (var key in fieldMapping) {\n generateUserPayloadField(userMetadata, payload, key, fieldMapping[key]);\n }\n\n return payload;\n }\n\n function updateRuleUser(user, updatedUser) {\n for (var key in fieldMapping) {\n if (typeof user.user_metadata[fieldMapping[key]] === 'string') {\n user[key] = updatedUser[key];\n delete user.user_metadata[fieldMapping[key]];\n }\n }\n }\n\n function generateUserPayloadField(userMetadata, payload, rootField, metadataField) {\n if (typeof userMetadata[metadataField] === 'string') {\n payload[rootField] = userMetadata[metadataField];\n payload.user_metadata[metadataField] = null;\n }\n }\n}"
289289
},
290290
{
291291
"id": "remove-attributes",

0 commit comments

Comments
 (0)