Closed sikancil closed 8 years ago
server.register() with hapi 15+ always calls its callback in nextTick, so the compose callback will always be called on nextTick if you register a plugin, regardless.
What is the failure condition that makes you not want the callback to be in nextTick?
Error: Unknown authentication strategy private_jwt in /restricted
which in my understanding that the auth-strategy
are failed (might late; or not applied to routes) to implement from auth-scheme
in specific connection (or all).
Test case:
var __instances = [ 'private', 'public' ];
var glueParams = {
manifest: {
connections: [
{ host: 'sikancil.dev', port: 9810, labels: [ 'private' ] },
{ host: 'web.sikancil.dev', port: 9820, labels: [ 'public' ] }
],
registrations: [
{ plugin: 'inert', options: { select: [ 'private', 'public' ] } },
{ plugin: 'vision', options: { select: [ 'public' ] } },
{ plugin: 'hapi-auth-jwt2', options: { select: [ 'private' ] } },
{ plugin: 'yar', options: { select: [ 'private' ] } }
]
},
options: {
relativeTo: __dirname
}
};
glue.compose( glueParams.manifest, glueParams.options, function (glueError, glueServer) {
_.forEach(__instances, function (instance, idx) {
console.log('[hapi-auth-jwt2] plugins is available? ', _.has(glueServer.select(instance).registrations, 'hapi-auth-jwt2'));
console.log('[hapi-auth-jwt2] auth-scheme is available? ',
(function () {
try { glueServer.auth.scheme('jwt'); return false; }
catch (e) { return true; }
}())
);
if (_.has(glueServer.select(instance).registrations, 'hapi-auth-jwt2')) {
glueServer.select(instance).auth.strategy(
instance + '_jwt', //-- strategy name; << HERE the Error: Unknown authentication strategy private_jwt in /restricted
'jwt', //-- auth-scheme
true,
{
key: '1234',
validateFunc: function (decoded, request, callback) {
//-- assume auth validation is OK
return true;
},
verifyOptions: {algorithms: ['HS256']},
cookieKey: 'testGlue'
}
);
}
});
glueServer.route({
method: 'GET',
path: '/restricted',
config: {
auth: 'private_jwt', //-- strategy name; << HERE the Error: Unknown authentication strategy private_jwt in /restricted
app: {
name: 'private'
}
},
vhost: 'sikancil.dev',
handler: function($req, $reply){
return $reply({
message: 'Hello, you were using <private> connection'
});
}
});
app.server.start(function(error) {
if (error) { throw error }
console.log('Server started!');
});
});
It seems you are adding the route for all connections, but the private_jwt strategy is only private connection. Probably try to select down to only that one connection and you should be good. Lacking that, I suggest moving this question over to hapijs/discuss for a broader audience. This isn't a problem with the callback being in nextTick, but at usage issue.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
Referencing issue for
auth
plugins required with some different configurations on each connections.Need to call
server.auth.strategy()
for single connection and/orconnection.auth.strategy
, right after preferred auth plugin registered beforenext(err)
tick.eg:
L117 - L120
https://github.com/dwyl/hapi-auth-jwt2/issues/198#issuecomment-252562072