I’m trying to initialize a SAML strategy during the require line. Something like this:
JavaScript
x
5
1
var myStrat = new require('passport-something').Strategy(
2
{ . }
3
);
4
passport.use('something', myStrat);
5
but am getting the error:
JavaScript
1
7
1
/passport/lib/authenticator.js:54
2
if (!name) { throw new Error('Authentication strategies must have a name'); }
3
^
4
5
Error: Authentication strategies must have a name
6
at Authenticator.use
7
or TypeError: Cannot read property 'name' of undefined at Authenticator.use
if a custom strategy name is not defined: passport.use(myStrat);
.
I’ve had it like this (which works):
JavaScript
1
6
1
var mySomething = require('passport-something');
2
var myStrat = new mySomething.Strategy(
3
{ . }
4
);
5
passport.use(myStrat);
6
but I wish to change it because I need to call passport-saml’s Stragety.generateServiceProviderMetadata()
function later on.
Which (I think) mean I need a variable pointing to the new Strategy instance.
Not a big deal I know, just would like to have the code for this particular strategy look more in line with the rest if I can. Which all look like:
JavaScript
1
5
1
var GoogleStrat = require( 'passport-google-oauth2' ).Strategy;
2
passport.use('google', new GoogleStrat(
3
.
4
));
5
Advertisement
Answer
this should work:
JavaScript
1
5
1
var myStrat = require('passport-something').Strategy(
2
{ . }
3
);
4
passport.use('something', new myStrat());
5
or, if you want to hold the instance:
JavaScript
1
5
1
var myStratInstance = new (require('passport-something').Strategy)(
2
{ . }
3
);
4
passport.use('something', myStratInstance);
5