fix policy configs

pull/13/head
unknown 2018-10-31 14:54:38 -04:00
parent f607083455
commit eea3976cb6
3 changed files with 32 additions and 11 deletions

29
api/policies/passport.js Normal file
View File

@ -0,0 +1,29 @@
/**
* Passport Middleware
*
* Policy for Sails that initializes Passport.js and as well as its built-in
* session support.
*
* For more information on the Passport.js middleware, check out:
* http://passportjs.org/guide/configure/
*/
const http = require('http')
const methods = ['login', 'logout', 'isAuthenticated', 'isUnauthenticated']
module.exports = async function (req, res, next) {
const passport = (await sails.helpers.passport()).getPassport()
passport.initialize()(req, res, function () {
passport.session()(req, res, function () {
if (req.isSocket) {
_.each(methods, function (method) {
req[method] = http.IncomingMessage.prototype[method].bind(req)
})
}
req.locals.user = req.user
next()
})
})
}

View File

@ -18,15 +18,7 @@ module.exports.policies = {
***************************************************************************/
'*': [
'basicAuth',
'passport',
'sessionAuth',
'ModelPolicy',
'AuditPolicy',
'OwnerPolicy',
'PermissionPolicy',
'RolePolicy',
'CriteriaPolicy'
'passport'
],
AuthController: {

View File

@ -2,7 +2,7 @@
const crypto = require('crypto')
const base64URL = require('base64url')
module.exports = {
module.exports.protocols = {
local: {
/**
* Validate a login request
@ -31,7 +31,7 @@ module.exports = {
user: user.id
})
if (passport) {
const res = await passport.validatePassword(password)
const res = await Passport.validatePassword(password, passport)
if (!res) throw new Error('incorrect password')
return next(null, user, passport)
}