panva / jose

JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes
MIT License
5.62k stars 315 forks source link

JWKS Timeout : request timed out #596

Closed ra-kesh closed 1 year ago

ra-kesh commented 1 year ago

What happened?

Getting the below request timeout error while trying to verify using a public JSON Web Key Set with next js 13 app router middlware and hanko . It was working perfectly fine 2 days ago but suddenly it's giving timeout most of the time now

 [JWKSTimeout: request timed out] {
  code: 'ERR_JWKS_TIMEOUT',
  name: 'JWKSTimeout',
  message: 'request timed out'
}

Version

4.15.3

Runtime

Browser

Runtime Details

Next 13.5.6

Code to reproduce

import { NextResponse, NextRequest } from "next/server";

import { jwtVerify, createRemoteJWKSet } from "jose";

const hankoApiUrl = process.env.NEXT_PUBLIC_HANKO_API_URL;

export async function middleware(req: NextRequest) {
  const hanko = req.cookies.get("hanko")?.value;

  const JWKS = createRemoteJWKSet(
    new URL(`${hankoApiUrl}/.well-known/jwks.json`)
  );

  try {
    const verifiedJWT = await jwtVerify(hanko ?? "", JWKS);

  } catch (error) {
    console.error(error)
    return NextResponse.redirect(new URL("/login", req.url));
  }
}

Required

panva commented 1 year ago

It was working perfectly fine 2 days ago but suddenly it's giving timeout most of the time now

That's something to take up with your Network, its settings, and/or the operator of the JSON Web Key Set service.