Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/deploy fixes #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-{{ checksum "package-lock.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm i
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
key: v1-dependencies-{{ checksum "package-lock.json" }}
- run: npm run test
- persist_to_workspace:
root: .
Expand All @@ -30,7 +30,7 @@ jobs:
at: .
- restore_cache:
keys:
- npm-circleci-{{ checksum "package.lock" }}
- npm-circleci-{{ checksum "package-lock.json" }}
- npm-circleci-
- run:
name: Install Serverless CLI and dependencies
Expand All @@ -41,8 +41,7 @@ jobs:
- node_modules
- run:
name: Build and deploy lambda package
command: |
node .circlecli/bin/node_modules/serverless/bin/serverless deploy
command: npm run ci-deploy

workflows:
version: 2.1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ jspm_packages
# Optional REPL history
.node_repl_history
*.zip

#Serverless
.serverless
23 changes: 19 additions & 4 deletions lib/auth0tools.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var auth0 = require('auth0');
const auth0 = require('auth0');
const ManagementClient = auth0.ManagementClient;
const isurl = require('isurl');

module.exports = {
async addAuth0Url(credentials, url) {

if (typeof credentials.Auth0ClientDomain === 'undefined') {
throw new Error('Auth0ClientDomain is required in the credentials parameter');
}
Expand All @@ -18,6 +20,15 @@ module.exports = {
if (typeof url === 'undefined') {
throw new Error('url is required');
}

const protoRegex = /^((http|https):\/\/)/;
if (!protoRegex.test(url)) {
url = `https://${ url }`;
}
if (!isurl(new URL(url))) {
throw new Error(`${ url } is not a valid url`);
}

const mgmt = new ManagementClient({
domain: credentials.Auth0ClientDomain,
clientId: credentials.Auth0MgmtApiClientId,
Expand All @@ -26,14 +37,18 @@ module.exports = {
const client = await mgmt.getClient({
client_id: credentials.Auth0ClientID,
});
// Array <--> Set swapparoo to remove duplicates :tophat:
const callbacks = [...new Set(client.callbacks.concat([`${ url }/authenticated`]))];
const web_origins = [...new Set(client.web_origins.concat([url]))];
const allowed_logout_urls = [...new Set(client.allowed_logout_urls.concat([url]))];
return mgmt.updateClient(
{
client_id: credentials.Auth0ClientID,
},
{
callbacks: client.callbacks.concat([`${ url }/authenticated`]),
web_origins: client.web_origins.concat([url]),
allowed_logout_urls: client.allowed_logout_urls.concat([url]),
callbacks,
web_origins,
allowed_logout_urls,
},
).then(result => {
return result;
Expand Down
27 changes: 14 additions & 13 deletions lib/handler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var secrets = require('./secrets');
// Known bug with rewire. Need to cast as var
var auth0tools = require('./auth0tools');
// eslint-disable-next-line no-var
var secrets = require('./secrets');
// eslint-disable-next-line no-var
var auth0tools = require('./auth0tools');
const Promise = require('bluebird');

const handler = async (event, context) => {
const handler = async(event, context) => {
if (typeof event.secretEnv === 'undefined') {
throw new Error('secretEnv is required');
}
Expand All @@ -16,14 +18,13 @@ const handler = async (event, context) => {
return await auth0tools.addAuth0Url(secret, url);
};

module.exports = function(event, context, cb) {
return Promise.try(() => handler(event, context))
.then(result => {
cb(null);
return result;
})
.catch(err => {
cb(err);
throw err;
});
module.exports = async(event, context, cb) => {
try {
const result = await Promise.try(() => handler(event, context));
cb(null);
return result;
} catch (err) {
cb(err);
throw err;
}
};
Loading