This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #12 from ministryofjustice/ag--auth0-hosted-login-…
…page Use Auth0 hosted login page.
- Loading branch information
Showing
11 changed files
with
1,224 additions
and
2,166 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,20 @@ | ||
module.exports = { | ||
"extends": "airbnb-base", | ||
"env": { | ||
"browser": true, | ||
"mocha": true, | ||
}, | ||
"globals": { | ||
"$": false, | ||
"moj": true, | ||
}, | ||
"rules": { | ||
"camelcase": ["off"], | ||
"no-alert": ["off"], | ||
"import/no-dynamic-require": ["off"], | ||
"no-use-before-define": ["error", { "classes": false }], | ||
"object-curly-newline": ["error", { "consistent": true }], | ||
"no-param-reassign": ["error", { "props": false }], | ||
"no-underscore-dangle": ["error", { "allow": ["_json"] }], | ||
} | ||
}; |
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,4 +1,4 @@ | ||
FROM node:6.11-alpine | ||
FROM node:8.9.4-alpine | ||
|
||
WORKDIR /app | ||
|
||
|
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,40 +1,49 @@ | ||
var config = module.exports; | ||
const config = module.exports; | ||
|
||
|
||
config.app = { | ||
protocol: process.env.APP_PROTOCOL || 'http', | ||
host: process.env.APP_HOST || 'localhost:3000', | ||
}; | ||
|
||
config.express = { | ||
port: process.env.EXPRESS_PORT || 3000, | ||
host: process.env.EXPRESS_HOST || '127.0.0.1' | ||
host: process.env.EXPRESS_HOST || '127.0.0.1', | ||
}; | ||
|
||
config.log = { | ||
level: process.env.LOG_LEVEL || 'debug' | ||
level: process.env.LOG_LEVEL || 'debug', | ||
}; | ||
|
||
config.session = { | ||
secret: process.env.COOKIE_SECRET || 'shh-its-a-secret', | ||
name: 'session', | ||
resave: true, | ||
saveUninitialized: true | ||
saveUninitialized: true, | ||
secret: process.env.COOKIE_SECRET || 'shh-its-a-secret', | ||
}; | ||
|
||
config.auth0 = { | ||
domain: process.env.AUTH0_DOMAIN, | ||
callbackURL: process.env.AUTH0_CALLBACK_URL || 'http://localhost:3000/callback', | ||
clientID: process.env.AUTH0_CLIENT_ID, | ||
clientSecret: process.env.AUTH0_CLIENT_SECRET, | ||
callbackURL: process.env.AUTH0_CALLBACK_URL || 'http://localhost:3000/callback' | ||
domain: process.env.AUTH0_DOMAIN, | ||
passReqToCallback: true, | ||
scope: 'profile', | ||
sso_logout_url: '/v2/logout', | ||
}; | ||
|
||
config.proxy = { | ||
target: { | ||
host: process.env.PROXY_TARGET_HOST, | ||
port: process.env.PROXY_TARGET_PORT | ||
port: process.env.PROXY_TARGET_PORT, | ||
}, | ||
ws: true, | ||
preserveHeaderKeyCase: true, | ||
proxyTimeout: process.env.PROXY_TIMEOUT || (24 * 60 * 60 * 1000) | ||
proxyTimeout: process.env.PROXY_TIMEOUT || (24 * 60 * 60 * 1000), | ||
}; | ||
|
||
config.rstudio = { | ||
user: process.env.RSTUDIO_USER || process.env.USER, | ||
duration: (24 * 60 * 60 * 1000), | ||
key: process.env.SECURE_COOKIE_KEY | ||
key: process.env.SECURE_COOKIE_KEY, | ||
}; |
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,6 +1,6 @@ | ||
// catch 404s and forward to error handler | ||
module.exports = function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
module.exports = (req, res, next) => { | ||
const err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
} | ||
}; |
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,50 +1,51 @@ | ||
require('dotenv').config(); | ||
var bole = require('bole'); | ||
var config = require('./config'); | ||
var morgan = require('morgan'); | ||
var nunjucks = require('nunjucks'); | ||
var passport = require('passport'); | ||
var path = require('path'); | ||
var Auth0Strategy = require('passport-auth0'); | ||
const bole = require('bole'); | ||
const express = require('express'); | ||
const morgan = require('morgan'); | ||
const passport = require('passport'); | ||
const path = require('path'); | ||
const Auth0Strategy = require('passport-auth0-openidconnect').Strategy; | ||
|
||
const config = require('./config'); | ||
const errors = require('./errors'); | ||
const routes = require('./routes'); | ||
|
||
var app = require('express')(); | ||
|
||
const app = express(); | ||
app.set('views', path.join(__dirname, 'views')); | ||
|
||
// add before logging to avoid favicon requests in logs | ||
app.use(require('serve-favicon')(path.join(__dirname, 'favicon.ico'))); | ||
|
||
bole.output({level: config.log.level, stream: process.stdout}); | ||
bole.output({ level: config.log.level, stream: process.stdout }); | ||
app.use(morgan('combined')); | ||
|
||
nunjucks.configure(path.join(__dirname, 'views'), { | ||
autoescape: true, | ||
express: app | ||
}); | ||
|
||
app.use(require('cookie-parser')()); | ||
app.use(require('express-session')(config.session)); | ||
|
||
passport.use(new Auth0Strategy( | ||
const strategy = new Auth0Strategy( | ||
config.auth0, | ||
function(accessToken, refreshToken, extraParams, profile, done) { | ||
return done(null, profile); | ||
} | ||
)); | ||
((req, issuer, audience, profile, accessToken, refreshToken, params, callback) => { | ||
req.session.id_token = params.id_token; | ||
|
||
return callback(null, profile._json); | ||
}), | ||
); | ||
passport.use(strategy); | ||
|
||
passport.serializeUser(function(user, done) { | ||
passport.serializeUser((user, done) => { | ||
done(null, user); | ||
}); | ||
|
||
passport.deserializeUser(function(user, done) { | ||
passport.deserializeUser((user, done) => { | ||
done(null, user); | ||
}); | ||
|
||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
|
||
app.use(require('./routes')); | ||
app.use(require('./errors')); | ||
app.use(routes); | ||
app.use(errors); | ||
|
||
|
||
module.exports = app; |
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,24 +1,22 @@ | ||
var config = require('./config'); | ||
const config = require('../config'); | ||
const log = require('bole')('middleware'); | ||
|
||
|
||
module.exports.denyUnauthorized = function (req, res, next) { | ||
|
||
if (isAuthorized(req)) { | ||
next(); | ||
|
||
} else { | ||
res.sendStatus(403); | ||
next(new Error('User is not authorized')); | ||
} | ||
}; | ||
|
||
function isAuthorized(req) { | ||
try { | ||
return req.user.nickname.toLowerCase() === config.rstudio.user; | ||
|
||
} catch (error) { | ||
// do nothing | ||
log.error('Error while checking user nickname: ', error); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
module.exports = function (req, res, next) { | ||
if (isAuthorized(req)) { | ||
next(); | ||
} else { | ||
res.sendStatus(403); | ||
next(new Error('User is not authorized')); | ||
} | ||
}; |
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.
Oops, something went wrong.