trailsjs / sails-auth

Passport-based User Authentication system for sails.js applications. Designed to work well with the sails-permissions module.
https://www.npmjs.org/package/sails-auth
MIT License
266 stars 141 forks source link

Protocol additions and changes are ignored #79

Closed kevintechie closed 6 years ago

kevintechie commented 9 years ago

When adding support for a new authentication provider and protocol, I discovered that the protocol files created by the generator in /api/services/protocols are ignored by the protocols require statement in the node_modules/sails-auth/api/services/passport.js.

I was able to resolve this by overriding the protocols method by adding the following line to the /api/services/passport.js file:

protocols: require('./protocols')

This changes the path for the require statement to one that's relative to the project rather than relative to the package install location.

tjwebb commented 9 years ago

@kevintechie have you looked at the protocols index? https://github.com/tjwebb/sails-auth/blob/master/api/services/protocols/index.js

kevintechie commented 9 years ago

Yes. You have to do both, override the protocols require statement and add the new protocol to the project-local protocols/index.js file.

samlroberts commented 8 years ago

Does anyone have a good workaround for this right now? I'd rather not have to edit files within my node_modules folder for my project.

elennaro commented 8 years ago

@kevintechie, can you please explain more detailed, how to override the protocols require statement?

kevintechie commented 8 years ago

@elennaro,

There's nothing more to overriding the protocols require statement than adding the line I mentioned.

This is needed because the sails-auth module references the protocols directory relative to its local passport.js file. Using the override in your project's passport.js file causes the protocol files to be referenced relative to your project.

-// api/services/passport.js        
-'use strict';      
-var _ = require('lodash');     
-var _super = require('sails-auth/api/services/passport'); // eslint-disable-line no-underscore-dangle, no-inline-comments      
-       
-function passport() {      
-}      
-       
-passport.prototype = Object.create(_super);        
-_.extend(passport.prototype, {     
-       
-  // Extend with custom logic here by adding additional fields and methods,        
-  // and/or overriding methods in the superclass.      
-  protocols: require('./protocols')        
-       
-});        
-       
-module.exports = new passport(); // eslint-disable-line new-cap, no-inline-comments
elennaro commented 8 years ago

@kevintechie Thank you very much! I'll give it a try!

pixelbacon commented 6 years ago

@elennaro Have you gotten this to work?

elennaro commented 6 years ago

@pixelbacon It was years ago, I can barely recall... I've binded 'passport-jwt' somehow...

pixelbacon commented 6 years ago

@kevintechie After implementing this, still getting JwtStrategy requires a verify callback

kevintechie commented 6 years ago

@pixelbacon I'm sorry to say that I've recycled all the brain cells I used for Sails.js long ago. However, it's not clear that your error is related to the issue here. You may want to check #147 for more hints.