-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validateFunc function is not excuted or not called #204
Comments
Hi @rssandy1991 can you please give us a bit more detail? If your code is open, please share a link to it, if not, can you paste a snippet of your server.js and 'validateFunc' here as a comment so we can help debug thanks! |
***validateFunc function is not excuted and Request is send to server then validateFunc fuction is not excuted and Unauthorized request display in chrome console. *** server.js code as below 'use strict'; var people = {
};
};
}); server.start(function (err) { Routes.js code show as below var listings=require('../controllers/listings'); |
front end Code $http.get('http://localhost:3000/listings/', { |
I seem to be having a similar problem. I am trying to use Auth0 and hapi-auth-jwt2 but I am getting this error: This is my authentication.js which I have registered in my server setup file: var env = require('env2')('.env');
var HapiAuthJWT = require('hapi-auth-jwt2');
var validate = function (decoded, request, callback) {
console.log("decoded------------->",decoded);
if (!decoded) {
return callback(null, false);
} else {
return callback(null, true);
}
}
exports.register = function (server, options, next) {
server.register(HapiAuthJWT, function (err) {
server.auth.strategy('jwt', 'jwt', {
key: Buffer(process.env.AUTH0_CLIENT_SECRET, 'base64'),
validateFunc: validate,
verifyOptions: {
algorithms: [ 'HS256' ],
audience: process.env.AUTH0_CLIENT_ID
}
});
server.auth.default('jwt');
});
return next();
};
exports.register.attributes = {
name: 'Authentication'
}; These are my routes which are also registered in my server setup file: module.exports = [
{
method: 'GET',
path: '/create-an-account',
config: {
auth: false
},
handler: function(request, reply) {
var data = {
siteWideVariables: siteWideVariables
};
return reply.view('create-an-account', data);
}
},
{
method: 'POST',
path: '/create-an-account',
config: {
auth: false,
validate: {
payload: {
fullName: Joi.string().required(),
email: Joi.string().required().email(),
mobileNumber: Joi.string().min(10).required(),
token: Joi.string().required()
},
failAction: createAccountValidateHandler
},
handler: createAccountValidateHandler
}
},
{
method: 'GET',
path: '/create-an-account/make-sure-this-is-right',
handler: function(request, reply) {
var data = {
siteWideVariables: siteWideVariables,
email: request.state.account.email
};
return reply.view('make-sure-this-is-right', data);
}
}
]
function createAccountValidateHandler(request, reply, source, error) {
var data = validationHelper.checkForErrors(request, error);
if (typeof data !== "undefined"){
data.siteWideVariables = siteWideVariables;
return reply.view('create-an-account', data).code(400);
} else {
return reply.redirect('/create-an-account/make-sure-this-is-right')
.state('account', request.payload, {path: '/'})
.header("Authorization", request.payload.token);
}
} When I get to the last endpoint which requires authentication nothing is getting into my validate function, I assume that is why I cannot access the endpoint. Any help with what I could be doing wrong would be greatly appreciated. Thanks! |
Reading through the closed issues it looks like #125 partly answers my question- Using https://jwt.io/ I can see that I don't have a valid JWT so the validate function will not run, however I'm not sure why my JWT is not valid |
Any updates? I am getting the same issue. @rug1 As per your last comment, In case, if you have invalid JWT it should update like Invalid JWT instead of missing authentication. |
Request is send to server then validateFunc fuction is not excuted and Unauthorized request display in chrome console.
The text was updated successfully, but these errors were encountered: