This repository has been archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
55 lines (45 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const Trailpack = require('trailpack')
const lib = require('./lib')
const _ = require('lodash')
module.exports = class PassportTrailpack extends Trailpack {
/**
* Check express4 is used and verify session configuration
*/
validate() {
if (!_.includes(_.keys(this.app.packs), 'express')) {
return Promise.reject(new Error('This Trailpack work only for express !'))
}
if (!_.includes(_.keys(this.app.packs), 'waterline') && !_.includes(_.keys(this.app.packs), 'sequelize') && !_.includes(_.keys(this.app.packs), 'mongoose')) {
return Promise.reject(new Error('This Trailpack work only with waterline, sequelize or mongoose!'))
}
if (!this.app.config.passport) {
return Promise.reject(new Error('No configuration found at config.passport !'))
}
const strategies = this.app.config.passport.strategies
if (!strategies || (strategies && Object.keys(strategies).length == 0)) {
return Promise.reject(new Error('No strategies found at config.passport.strategies !'))
}
if (strategies.jwt && _.get(this.app, 'config.passport.jwt.tokenOptions.secret') === 'mysupersecuretoken') {
return Promise.reject(new Error('You need to change the default token !'))
}
return Promise.all([
lib.Validator.validatePassportsConfig(this.app.config.passport)
])
}
/**
* Initialise passport functions and load strategies
*/
configure() {
lib.Passports.init(this.app)
lib.Passports.loadStrategies(this.app)
lib.Passports.addRoutes(this.app)
}
constructor(app) {
super(app, {
config: require('./config'),
api: require('./api'),
pkg: require('./package')
})
}
}