This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from garden-aid/develop
Protect endpoints with auth0
- Loading branch information
Showing
35 changed files
with
729 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ coverage | |
|
||
webpack/* | ||
public/dist/* | ||
src/auth/policy.js | ||
|
||
gulpfile.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
extends: airbnb | ||
plugins: | ||
- react | ||
- jsx-a11y | ||
- import | ||
|
||
env: | ||
mocha: true | ||
node: true | ||
|
||
rules: | ||
no-console: 0 | ||
strict: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ env: | |
|
||
before_install: | ||
- npm i -g snyk | ||
- npm i -g serverless@beta | ||
- npm i -g serverless | ||
|
||
script: ./deploy.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"moistureTableName": "moisture-data-dev" | ||
"MOISTURE_TABLE_NAME": "moisture-data-dev", | ||
"AUTH0_DOMAIN": "johncmckim.au.auth0.com", | ||
"AUTH0_CLIENT_ID": "SWLx5XS17ssom0DCuTPlDlXnJUbTXbiP" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"moistureTableName": "moisture-data-dev" | ||
"MOISTURE_TABLE_NAME": "moisture-data-dev", | ||
"AUTH0_DOMAIN": "johncmckim.au.auth0.com", | ||
"AUTH0_CLIENT_ID": "SWLx5XS17ssom0DCuTPlDlXnJUbTXbiP" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"moistureTableName": "moisture-data-production" | ||
"MOISTURE_TABLE_NAME": "moisture-data-production", | ||
"AUTH0_DOMAIN": "johncmckim.au.auth0.com", | ||
"AUTH0_CLIENT_ID": "SWLx5XS17ssom0DCuTPlDlXnJUbTXbiP" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const _ = require('lodash'); | ||
|
||
const envVars = [ | ||
'IOPIPE_KEY', | ||
]; | ||
|
||
const secrets = _.pick(process.env, envVars); | ||
const secretKeys = Object.keys(secrets); | ||
|
||
const iopipeKey = process.env.IOPIPE_KEY; | ||
console.log('Writing env vars ', secretKeys); | ||
|
||
if (!iopipeKey) { | ||
throw new Error('Please set IOPIPE_KEY env var'); | ||
if (!_.isEqual(envVars, secretKeys)) { | ||
throw new Error('Missing some env vars'); | ||
} | ||
|
||
const secrets = { | ||
iopipeKey: iopipeKey | ||
}; | ||
_.forEach(secrets, (secret, key) => { | ||
if (!secret) { | ||
throw new Error(`${key} is required`); | ||
} | ||
}); | ||
|
||
const secretsPath = path.resolve(__dirname, './secrets.json'); | ||
|
||
fs.writeFileSync(secretsPath, JSON.stringify(secrets)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
|
||
module.exports = function(config, secure) { | ||
Object.keys(config).forEach((key, index) => { | ||
module.exports = (config, secure) => { | ||
Object.keys(config).forEach((key) => { | ||
const value = config[key]; | ||
process.env[key] = value; | ||
|
||
console.log(`Env: ${key}=${secure ? 'secure' : value}`) | ||
console.log(`Env: ${key}=${secure ? 'secure' : value}`); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
const AuthPolicy = require('./policy').AuthPolicy; | ||
|
||
module.exports.authorize = (token, auth0Client, authInfo) => | ||
auth0Client.tokens.getInfo(token) | ||
.then((userInfo) => { | ||
if (!userInfo || !userInfo.user_id) { | ||
throw new Error('No user_id returned from Auth0'); | ||
} | ||
|
||
console.log(`Building policy for ${userInfo.user_id} with: `, authInfo); | ||
|
||
const policy = new AuthPolicy(userInfo.user_id, authInfo.accountId, authInfo); | ||
|
||
policy.allowMethod(AuthPolicy.HttpVerb.POST, '/graphql'); | ||
|
||
const result = policy.build(); | ||
console.log('Returning auth result: ', result, result.policyDocument.Statement); | ||
|
||
return result; | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
return 'Unauthorized'; | ||
}); |
Oops, something went wrong.