-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from matthewglover/clean-up
Clean up
- Loading branch information
Showing
13 changed files
with
138 additions
and
46 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "airbnb", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}] | ||
} | ||
} |
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,24 @@ | ||
const { createServer, setConnection, registerPlugins, addRoutes, startServer } = | ||
require('@matthewglover/hapi-wrapper'); | ||
const oauthPlugin = require('./oauth_plugin'); | ||
const jwtPlugin = require('./jwt_plugin'); | ||
|
||
const protectedRoute = { | ||
method: 'GET', | ||
path: '/protected', | ||
config: { auth: 'jwt' }, | ||
handler: (req, reply) => reply('boom'), | ||
}; | ||
|
||
const server = | ||
createServer() | ||
.then(setConnection({ port: 3000 })) | ||
.then(registerPlugins([oauthPlugin, jwtPlugin])) | ||
.then(addRoutes([protectedRoute])) | ||
.then(startServer) | ||
/* eslint-disable no-console */ | ||
.then(s => console.log(`Server running at: ${s.info.uri}`)) | ||
.catch(err => console.error(err)); | ||
/* eslint-enable */ | ||
|
||
module.exports = server; |
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,21 @@ | ||
require('env2')('./config.env'); | ||
const hapiJwt = require('../'); | ||
|
||
/* eslint-disable max-len */ | ||
const options = { | ||
strategyName: 'jwt', // Name of strategy (defaults to jwt) | ||
|
||
createTokenPath: '/create-token', // Path for token creation | ||
prepareTokenData: req => req.query, // Function to prepare token payload data | ||
|
||
issueTokenPath: '/issue-token.html', // Path which will issue token (as /issue-token.html?jwt=[token]) | ||
|
||
verifyTokenPath: '/verify-token', // Path which will verify token (as /verify-token?jwt=[token]) | ||
|
||
jwtOptions: { algorithm: 'HS256' }, // jwt creation options (as per jsonwebtoken.sign) | ||
jwtVerificationOptions: { algorithm: 'HS256' }, // jwt verification options (as per jsonwebtoken.verify) | ||
jwtSecret: process.env.JWT_SECRET, // secret for creating token | ||
}; | ||
/* eslint-enable max-len */ | ||
|
||
module.exports = { register: hapiJwt, options }; |
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,21 @@ | ||
require('env2')('./config.env'); | ||
const hapiOauth = require('@matthewglover/hapi-oauth'); | ||
|
||
const options = { | ||
configs: [ | ||
{ | ||
provider: 'facebook', | ||
loginPath: '/fb-login', | ||
authPath: '/fb-auth', | ||
redirectPath: '/create-token', | ||
baseUrl: process.env.BASE_URL, | ||
clientId: process.env.FB_CLIENT_ID, | ||
clientSecret: process.env.FB_CLIENT_SECRET, | ||
options: { | ||
scope: 'user_likes', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
module.exports = { register: hapiOauth, options }; |
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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
|
||
<script type="text/javascript"> | ||
|
||
</script> | ||
</body> | ||
</html> |
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 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,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title></title> | ||
</head> | ||
<body> | ||
<a id="verifyTokenLink" href="#">verify token</a><br><br> | ||
<a id="accessProtectedLinkFail" href="#">access protected without jwt</a><br><br> | ||
<a id="accessProtectedLinkSuccess" href="#">access protected with jwt</a> | ||
|
||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
<script type="text/javascript"> | ||
const params = | ||
window.location.search | ||
.match(/[^?&]+/g) | ||
.map(s => s.split('=')) | ||
.reduce((acc, [k, v]) => Object.assign(acc, { [k]: v }), {}); | ||
|
||
document.getElementById('verifyTokenLink').addEventListener('click', () => { | ||
axios | ||
.get(`/verify-token?jwt=${params.jwt}`) | ||
.then(({ data }) => data) | ||
.then(console.log.bind(console)); | ||
}); | ||
|
||
document.getElementById('accessProtectedLinkFail').addEventListener('click', () => { | ||
axios | ||
.get(`/protected`) | ||
.then(({ data }) => data) | ||
.then(data => console.log('succes:', data)) | ||
.catch(err => console.log('error:', err)); | ||
}); | ||
|
||
document.getElementById('accessProtectedLinkSuccess').addEventListener('click', () => { | ||
axios | ||
.get(`/protected`, { headers: { Authorization: `Bearer ${params.jwt}` } }) | ||
.then(({ data }) => data) | ||
.then(data => console.log('succes:', data)) | ||
.catch(err => console.log('error:', err)); | ||
}); | ||
|
||
|
||
</script> | ||
</body> | ||
</html> |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.