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.

Unknown authentication strategy jwt

See original GitHub issue

Good day.

I’m trying to run hapi, glue and jwt2. I found the example mentioned in FAQ, but I’m still not getting it to run. I have a prototype with 2 modules: auth and pinger(which replies pong). If I remove auth: ‘jwt’, server works, but no auth is required. If I add auth, I get error

Error: Unknown authentication strategy jwt in /pinger

auth/index.js

'use strict'

const hapiJwt = require('hapi-auth-jwt2')
const JWT_SECRET_KEY = '12345'

const register = function register (server, options, next) {
  server.register(hapiJwt)
  server.auth.strategy('jwt', 'jwt', true,
  { key: JWT_SECRET_KEY,
    validateFunc: (decoded, request, callback) => callback(null, true), // This should be replaced with a more robust function
    verifyOptions: { algorithms: [ 'HS256' ] }
  })

  server.auth.default('jwt')
  next()
}

register.attributes = {
  name: 'auth-wrapper',
  version: '0.0.1'
}

module.exports = register

pinger/index.js

exports.register = (server, options, next) => {

    server.route({
        path: '/pinger',
        method: 'GET',
        config: { auth: 'jwt' },
        handler: require('./pinger')
    });

    next();

};

exports.register.attributes = {
    pkg: {
      "name": "pinger",
      "version": "1.0.0"
    }
};

manifest.js

const Config = require('./config');

// Glue manifest
const manifest = module.exports = {

    server: {
        app: Config.app,
    },

    connections: [
        {
            host: Config.server.host,
            port: Config.server.port,
        },
    ],

    registrations: [
        {
            plugin: 'hapi-knex-objection-builder',
            plugin: './auth',
            plugin: './pinger'
        },
    ],

};

if (process.env.NODE_ENV === 'dev') {
    manifest.server.debug = {
        log: ['error', 'implementation', 'internal'],
        request: ['error', 'implementation', 'internal'],
    };
    manifest.registrations.push({
        plugin: {
            register: 'blipp',
        },
    });
}

if (process.env.NODE_ENV === 'production') {
    manifest.registrations.push({
        plugin: {
            register: 'poop',
            options: Config.poop,
        },
    });
}

And server, src/index.js

import { assert } from 'hoek';
import { compose } from 'glue';
import Labbable from 'labbable';
import Manifest from './config/manifest';

const labbable = module.exports = new Labbable();

const options = {
  relativeTo: __dirname + '/lib/modules'
};

compose(Manifest, options, (err, server) => {

    assert(!err, err);

    // Pass server along to labbable
    labbable.using(server);

    server.initialize((err) => {

        assert(!err, err);

        // No need to start server if this is being required (i.e. for testing)
        if (module.parent) {
            return;
        }

        server.start((err) => {

            assert(!err, err);

            console.log(`Server started at ${server.info.uri}`);
        });
    });
});

If config is needed, I can provide it. I have a feeling, that the auth plugin is not loaded. Anyway, this issue drives me up the wall. I could integrate the auth in the main file, but I don’t want to 😃

Can someone point me to a right direction? 😆

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
anttilinnocommented, Oct 10, 2016

Thank you for your effort. Seems, that glue is not the answer to all the prayers. I will try and re-structure my code without glue.

0reactions
anttilinnocommented, Oct 16, 2016

Ok, turns out I was registering plugins wrong. So, nothing wrong with glue or jwt2.

Correct way:

    registrations: [
        {
           { plugin: 'hapi-knex-objection-builder' },
           { plugin: './auth' },
           { plugin: './pinger' }
        },
    ],

Incorrect way:

    registrations: [
        {
            plugin: 'hapi-knex-objection-builder',
            plugin: './auth',
            plugin: './pinger'
        },
    ],

This n00b error cost me many hours and endless frustration 😃 Maybe it will shine some light to someone, who has somehow made same mistake.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "error": "Unknown authentication strategy \"jwt\""
I'm able to authenticate and generate a JWT, which I can parse on the JWT site, but for some reason, I'm getting an...
Read more >
Error: Unknown authentication strategy "jwt" · Issue #1868
I just updated to v6.0.4 and I'm using authguard with graphql & passport-jwt. However, I'm getting Error: Unknown authentication strategy ...
Read more >
Unknown authentication strategy "jwt" nestjs - You.com
Error : Unknown authentication strategy "jwt" #1868 - GitHub. Github.com > nestjs > nest. I just updated to v6.0.4 and I'm using authguard...
Read more >
Unknown authentication strategy "jwt" when I inject ... - Reddit
That error message means something's wrong with your Passport setup. Specifically: it is expecting a JWT strategy class to be available as a ......
Read more >
Error: Unknown authentication strategy "jwt"
created the profile route here i initiliazed and also used parer //just incase its needed app.use(bodyParser.urlencoded({extended:false})); ...
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