From 2ea2be85a2ee5d8f67d47e6727df4e8c368cba8c Mon Sep 17 00:00:00 2001 From: Tuana Celik Date: Fri, 23 Jul 2021 19:03:37 +0100 Subject: [PATCH] Cumul.io Rule (#296) * Cumul.io Rule Adding the rule here for the marketplace integration. Adds user_metadata.cumulio to id and access tokens to be used within cumulio. I've also added a warning as to this is what the integration does to the installation guideline markdown file. * Update src/rules/add-metadata-to-token.js Co-authored-by: Josh Cunningham * Resolving PR comments Co-authored-by: Josh Cunningham Co-authored-by: Josh Cunningham --- src/rules/a/cumulio-add-metadata-to-tokens.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/rules/a/cumulio-add-metadata-to-tokens.js diff --git a/src/rules/a/cumulio-add-metadata-to-tokens.js b/src/rules/a/cumulio-add-metadata-to-tokens.js new file mode 100644 index 00000000..a69ffb8e --- /dev/null +++ b/src/rules/a/cumulio-add-metadata-to-tokens.js @@ -0,0 +1,28 @@ +/** + * @title User metadata for Cumul.io + * @overview Add Cumul.io user metadata to tokens to be used for Cumul.io dashboard filtering + * @gallery true + * @category marketplace + * + * This integration simplifies the process of making full use of integrated Cumul.io dashboards' multi tenant features + * by using Auth0 as its authentication layer. The integration will allow you to set up and use user + * information in Auth0 to filter and structure your Cumul.io dashboards. + */ + + +function addMetadataToTokens(user, context, callback) { + const namespace = 'https://cumulio/'; + user.user_metadata = user.user_metadata || {}; + const cumulioMetadata = user.user_metadata.cumulio || {}; + if(typeof cumulioMetadata === 'object' && cumulioMetadata !== null){ + Object.keys(cumulioMetadata).forEach((k) => { + context.idToken[namespace + k] = cumulioMetadata[k]; + context.accessToken[namespace + k] = cumulioMetadata[k]; + }); + } + else{ + console.log("Make sure that user_metadata.cumulio is an object with keys and values"); + return; + } + callback(null, user, context); +}