From fe2d64de6e7f21610e19a8bacdf8c7594a0729ed Mon Sep 17 00:00:00 2001 From: Stuart Taylor Date: Thu, 3 May 2018 11:31:00 +0100 Subject: [PATCH 1/2] feat(tools): add visability of auth0 rules --- auth0-rules/README.md | 5 +++++ auth0-rules/add-accountLinkId-to-token.js | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 auth0-rules/README.md create mode 100644 auth0-rules/add-accountLinkId-to-token.js diff --git a/auth0-rules/README.md b/auth0-rules/README.md new file mode 100644 index 0000000..c07c918 --- /dev/null +++ b/auth0-rules/README.md @@ -0,0 +1,5 @@ +## Auth0 Rules + +The functions held in this directory have no direct effect inside the open-api, but are held here for visability and code review. + +They are subject to a manual deploy process, that is to say, we copy/paste them inside the Auth0 dashboard. diff --git a/auth0-rules/add-accountLinkId-to-token.js b/auth0-rules/add-accountLinkId-to-token.js new file mode 100644 index 0000000..86e6b70 --- /dev/null +++ b/auth0-rules/add-accountLinkId-to-token.js @@ -0,0 +1,20 @@ +/* eslint-disable */ + +/* + + Function name should be removed for deployment + + uuid is global inside Auth0 Rules + + https://auth0.com/docs/appliance/modules + +*/ + +function addAccountLinkId(user, context, callback) { + const namespace = 'https://www.freecodecamp.org/accountLinkId'; + user.app_metadata = user.app_metadata || {}; + user.app_metadata.accountLinkId = user.app_metadata.accountLinkId || uuid(); + context.idToken[namespace] = user.app_metadata.accountLinkId; + + callback(null, user, context); +} From fd3856f2c995b35fea4b5a41066fa7d82faf4401 Mon Sep 17 00:00:00 2001 From: Stuart Taylor Date: Thu, 3 May 2018 12:19:20 +0100 Subject: [PATCH 2/2] fix(ns): update ns --- auth0-rules/add-accountLinkId-to-token.js | 5 +++-- src/auth/index.js | 2 +- test/utils/test-environment.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/auth0-rules/add-accountLinkId-to-token.js b/auth0-rules/add-accountLinkId-to-token.js index 86e6b70..66887e4 100644 --- a/auth0-rules/add-accountLinkId-to-token.js +++ b/auth0-rules/add-accountLinkId-to-token.js @@ -11,10 +11,11 @@ */ function addAccountLinkId(user, context, callback) { - const namespace = 'https://www.freecodecamp.org/accountLinkId'; + const namespace = 'https://auth-ns.freecodecamp.org/'; user.app_metadata = user.app_metadata || {}; user.app_metadata.accountLinkId = user.app_metadata.accountLinkId || uuid(); - context.idToken[namespace] = user.app_metadata.accountLinkId; + context.idToken[namespace + 'accountLinkId'] = + user.app_metadata.accountLinkId; callback(null, user, context); } diff --git a/src/auth/index.js b/src/auth/index.js index df8b5e1..de8b7bd 100644 --- a/src/auth/index.js +++ b/src/auth/index.js @@ -8,7 +8,7 @@ const { JWT_CERT } = process.env; export { updateAppMetaData } from './auth0'; -export const namespace = 'https://www.freecodecamp.org/'; +export const namespace = 'https://auth-ns.freecodecamp.org/'; export const getTokenFromContext = ctx => ctx && diff --git a/test/utils/test-environment.js b/test/utils/test-environment.js index fd4ade9..96d316d 100644 --- a/test/utils/test-environment.js +++ b/test/utils/test-environment.js @@ -3,7 +3,7 @@ const NodeEnvironment = require('jest-environment-node'); // can be found in ~/src/auth/index.js // not 'required' due to jest no knowing how to read es6 modules -const namespace = 'https://www.freecodecamp.org/'; +const namespace = 'https://auth-ns.freecodecamp.org/'; const { JWT_CERT } = process.env;