question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with hapi-auth-jwt2

See original GitHub issue

If I add to my working code the npm module hapi-auth-jwt2, then all calls to /connect/provider returns 401. How I added it: as plugin in hapi require(‘hapi-auth-jwt2’) with a configuration

    server.auth.strategy('jwt', 'jwt', {
      key: config.JWT.SERIAL,
      validateFunc: jwt.validate,
      verifyOptions: {
        algorithms: [ config.JWT.ALGORITHM ],
        ignoreExpiration: true
      },
      headerKey: config.JWT.HEADER
    });

    server.auth.default('jwt');

Then the routes for grant have the configuration for disable jwt:

    config: {
      auth: false
    }

It returns the body {"statusCode":401,"error":"Unauthorized","message":"Missing authentication"} and the headers

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Token
content-type: application/json; charset=utf-8
cache-control: no-cache
vary: accept-encoding
content-encoding: gzip
Date: Wed, 26 Oct 2016 08:30:58 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Do you have an idea why this is happening and could it be resolved by me or you?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
TBoonXcommented, Jan 5, 2017

@Rub21 In your routes:

server.route({
        ..
        config: {
            ...
            auth: 'jwt'
        }
    });

in your server: (something like that)

server.auth.strategy('jwt', 'jwt', {
            key: SERIAL,
            validateFunc: validate,
            verifyOptions: {
                algorithms: [ALGORITHM],
                ignoreExpiration: true
            },
            headerKey: HEADER
        });
0reactions
Rub21commented, Jan 5, 2017

hey @TBoonX ,

enabling jwt just for routes which needs it.

how did you enable for specific routes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

hapi-auth-jwt2 - npm
Hapi.js Authentication Plugin/Scheme using JSON Web Tokens (JWT). Latest version: 10.2.0, last published: 2 years ago.
Read more >
hapi-auth-jwt2 works is not working in hapi.js app?
This is my server.js file and I run node server.js . 'use strict'; const Hapi = ...
Read more >
Simple example is not working · Issue #285 · dwyl/hapi-auth-jwt2
Hello,. I'm creating a simple example with hapi-auth-jwt2 and its not working, im getting this error whenever I send GET request through POSTMAN ......
Read more >
15 - JWT Strategy Auth and securing routes | restful API
Your browser can't play this video. ... https://hapi.dev/module/basic/#install hapi - auth - jwt2 : https://github.com/dwyl/ hapi - auth - jwt2 ...
Read more >
hapi-auth-jwt2 examples - CodeSandbox
Latest version10.2.0. LicenseISC ; Size71.204Kb. Packages Using it ; Issues Count370. Stars785.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found