requarks / wiki

Wiki.js | A modern and powerful wiki app built on Node.js
https://js.wiki
GNU Affero General Public License v3.0
24.44k stars 2.7k forks source link

Error Unknown authentication strategy "jwt" #1822

Closed fferraro87 closed 4 years ago

fferraro87 commented 4 years ago

Question I'm trying to install wiki.js on Plesk Obsidian with node.js support so i've download wiki.js.tar.gz and uncompressed on public folder then i've used node.js extension and i've set this configuration :

Node.js Version 12.4.0  
Document Root /httpdocs/assets    
Application Mode development  
Application URL http://wiki.underlow.com
Application Root /httpdocs  
Application Startup File server/index.js  
Custom environment variables nothing

On /httpdocs there is content of wikijs.tar.gz downloaded here https://github.com/Requarks/wiki/releases/download/2.3.81/wiki-js.tar.gz

So i open http://wiki.underlow.com and wiki js setup start and i set email, password and URI. After Installation complete, i open home page and i've that error :

Error: Unknown authentication strategy "jwt"
    at attempt (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/passport/lib/middleware/authenticate.js:190:39)
    at authenticate (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/passport/lib/middleware/authenticate.js:367:7)
    at authenticate (/var/www/vhosts/wiki.underlow.com/httpdocs/server/core/auth.js:173:7)
    at Layer.handle [as handle_request] (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:317:13)
    at /var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:335:12)
    at next (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:275:10)
    at initialize (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/passport/lib/middleware/initialize.js:53:5)
    at Layer.handle [as handle_request] (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:317:13)
    at /var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:335:12)
    at next (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:275:10)
    at session (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express-session/index.js:475:7)
    at Layer.handle [as handle_request] (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:317:13)
    at /var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:335:12)
    at next (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/index.js:275:10)
    at cookieParser (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/cookie-parser/index.js:71:5)
    at Layer.handle [as handle_request] (/var/www/vhosts/wiki.underlow.com/httpdocs/node_modules/express/lib/router/layer.js:95:5)

Host Info (please complete the following information): OS: Centos 7 Wiki.js version: 2.3.81 Database engine: 10.3.22-MariaDB

NGPixel commented 4 years ago

Just reload the page again and it should work. The initialization process was simply not finished by the time you loaded the page.

pasichnyi commented 4 years ago

That happens to me every time at the 'cold' load (after one day of nonvisiting page). Even though reload does the magic, it would not feel good for ordinary users. Is there any way to fix this permanently?

ClemensElflein commented 4 years ago

I have the same problem on my wikijs installation.

Smankusors commented 4 years ago

That happens to me every time at the 'cold' load (after one day of nonvisiting page). Even though reload does the magic, it would not feel good for ordinary users. Is there any way to fix this permanently?

CMIIW, but it's not the reload that does the magic. It's simply not finished loading stuff. You need to wait longer if you do cold load.

NGPixel commented 4 years ago

That happens to me every time at the 'cold' load (after one day of nonvisiting page). Even though reload does the magic, it would not feel good for ordinary users. Is there any way to fix this permanently?

You must be using a free Heroku instance? The solution is to upgrade to a plan where dynos don't sleep after X amount of time. Wiki.js isn't meant to be used in an environment that is not always on.

pasichnyi commented 4 years ago

You must be using a free Heroku instance? The solution is to upgrade to a plan where dynos don't sleep after X amount of time. Wiki.js isn't meant to be used in an environment that is not always on.

No, that's traditional (LAMP) virtual server-based hosting with NodeJS handled through CPanel. Is there any way to estimate sufficiency of hosting infrastructure in such case?

ClemensElflein commented 4 years ago

That happens to me every time at the 'cold' load (after one day of nonvisiting page). Even though reload does the magic, it would not feel good for ordinary users. Is there any way to fix this permanently?

You must be using a free Heroku instance? The solution is to upgrade to a plan where dynos don't sleep after X amount of time. Wiki.js isn't meant to be used in an environment that is not always on.

I have installed it on Plesk Obsidian 18.0.27 with the official Nodejs addon.

Edit: OP has the same issue and has also installed wikijs on Plesk. @fferraro87: Did you resolve the issue? If yes, how?

ClemensElflein commented 4 years ago

That happens to me every time at the 'cold' load (after one day of nonvisiting page). Even though reload does the magic, it would not feel good for ordinary users. Is there any way to fix this permanently?

CMIIW, but it's not the reload that does the magic. It's simply not finished loading stuff. You need to wait longer if you do cold load.

I can confirm that only reloading gets rid of the error message. If you open the site, the error occurs and does not disappear until you reload the page (I've waited for an hour just to be sure).

carcinocron commented 2 years ago

Error Unknown authentication strategy "jwt" is the only thing that stops wikijs from running great on Google Cloud Run, which is essentially free at most people's usage. I don't mind waiting 5 to 20 seconds for a cold start. $10/month to keep an idle server hot 24/7 is an exorbitant amount of money to pay. Dynamo looked like $25/month, I don't know much about heroku's pricing. The front-end javascript should just detect this specific error message and wait it out automatically. Crashing, red popups, and pressing refresh over and over again is a pretty bad user experience. Maybe it's possible to delay listening on the port until the server is ready?

e-jegat commented 1 week ago

Solution

I had exactly the same error Error Unknown authentication strategy "jwt" for exactly the same reason: I host Wiki.js on a managed environment (o2switch). The node application is managed by Phusion Passenger that shutdown application if no request is made during X amount of time.

When Wiki.js is shutdown and a new request comes, the Unknown authentication strategy "jwt" appears. If a new request is made just after, the error disappears and Wiki.js website is functional.

The boot of Wiki.js is done like this (kernel.js):

  1. Call to preBootMaster() function
  2. Loading of master.js
  3. Call to postBootMaster() function

The HTTP server is started at step 2, at the end of master.js. The passport strategies are initialized at step 3, inside the postBootMaster function.

In a managed environment, if Wiki.js is shutdown, the first request wakes up the application. The request starts to be handled when step 2 is done because the HTTP server is running. But, as the passport strategies have not yet been initialized (step 3), this first request fails during jwt validation.

I wrote a bypass to avoid this behavior that is not acceptable on my environment. The new boot process of the application is as follow:

  1. Call to preBootMaster() function => no change
  2. Loading of master.js but without HTTP server starting (the start of HTTP server is commented in master.js)
  3. Call to postBootMaster() function but with await operator to ensure that all the initialization is done
  4. Start the HTTP server: the code commented at step 2 in master.js is added in bootMaster() function

With theses changes, when the HTTP server starts at step 4, the passport strategies have been already loaded at step 3 and the jwt error does not occur anymore.

This solution works for me. I'm sure this doesn't fit in with the loading optimization philosophy as conceived by the application's creators, but it solves the error linked to the jwt strategy.

Details of changes

server/master.js: the start of HTTP and HTTPS servers are commented image

server/core/kernel.js: adding of await operator and adding of the HTTP and HTTPS server start after postBootMaster() call image

Files

files.zip

Hope this helps