Wednesday, 10 May 2017

Invalid header syntax when authentication using hapi-auth-hawk in nodejs

The problem is: when trying to hit a login functionality passing a token( which is generated before this step) in swagger, it throws Invalid Syntax error. Error screenshot is pasted below: enter image description here

Below is code snippet written in nodejs using hapi-auth-hawk for the strategy :

    server.auth.strategy('hawk', 'hawk', {
        getCredentialsFunc: getCredentials,
    });

    server.auth.strategy('jwt', 'jwt', config.auth.mode, {
         key: 'xxxxx',
         validateFunc: validate,
         ....
    });

Below is the actual login api which should be triggered( but now it is blocked because of the error Invalid header syntax) :

     server.route({
          method: "POST",
          path : '/api/login',
          config: {
            auth : 'hawk',
            handler: (request, reply) => {
            console.log("xxxxx");
            const clientID = request.auth.credentials.id;
            const tokenID = uuid.v4();

            const token = JWT.sign({
             scope: request.auth.credentials.scope,
             id: clientID,
             jtl: tokenID,
           }, "xxxxx");
          reply({ access_token: token });
        },
        tags: ['api'],
       validate: {
       options: {
            allowUnknown: true,
       },
       headers: {
            Authorization: Joi,
       },
      },
     },
   });

Any place where I am missing to include any header settings. Let me know if any further details are required.



via vsairam

No comments:

Post a Comment