Skip to content

Commit

Permalink
Merge pull request #18 from FACN1/require-authentic-on-all-routes-but…
Browse files Browse the repository at this point in the history
…-/login

#8 require authentication on all routes except for /login
  • Loading branch information
HilbertSpitzer authored Apr 13, 2017
2 parents e3b22a0 + 10786e4 commit 89c34fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const jwt = require('jsonwebtoken');
const staticFiles = {
method: 'GET',
path: '/{file}',
config: {
auth: {
strategy: 'jwt',
mode: 'optional'
}
},
handler: {
directory: {
path: path.join(__dirname, '../public')
Expand All @@ -18,6 +24,12 @@ const staticFiles = {
const loginButton = {
method: 'GET',
path: '/',
config: {
auth: {
strategy: 'jwt',
mode: 'optional'
}
},
handler: (request, reply) => {
const loginContent = {
text: 'Login'
Expand All @@ -31,6 +43,12 @@ const loginButton = {
const githubOAuth = {
method: 'GET',
path: '/login',
config: {
auth: {
strategy: 'jwt',
mode: 'optional'
}
},
handler: (request, reply) => {
const base = 'https://github.com/login/oauth/authorize?';
const oAuthParams = {
Expand All @@ -45,6 +63,12 @@ const githubOAuth = {
const welcome = {
method: 'GET',
path: '/welcome',
config: {
auth: {
strategy: 'jwt',
mode: 'optional'
}
},
handler: (request, reply) => {
const data = {
client_id: process.env.CLIENT_ID,
Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ server.register([inert, vision, hapiAuth], (err) => {
}
return callback(null, true);
};
server.auth.strategy('jwt', 'jwt', {
server.auth.strategy('jwt', 'jwt', 'required', {
key: process.env.SECRET,
validateFunc: validate,
verifyOptions: {
Expand Down

0 comments on commit 89c34fb

Please sign in to comment.