Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to verify token in a Next JS application on cloudflare #54

Open
konradbloor opened this issue Nov 28, 2024 · 0 comments
Open

Unable to verify token in a Next JS application on cloudflare #54

konradbloor opened this issue Nov 28, 2024 · 0 comments

Comments

@konradbloor
Copy link

konradbloor commented Nov 28, 2024

Hi, I'm using the edge runtime to run a next-on-pages application (next 14.2.5). I'm adding this issue here not because I have an expectation that the issue is fixed, just to bring attention to it.

On the server side I'm trying to validate the JWT in the authorization cookie in a route.ts API handler, and extract some information from it.

   const token = request.cookies.get("authorization")?.value;

    if (!token) {
      console.error("No authorization token found in cookies.");
      return new Response("Unauthorized", { status: 401 });
    }
    const authressClient = new AuthressClient({
      authressApiUrl: "https://auth.somedomain.com",
    });
    const decoded = await authressClient.verifyToken(token);

I get an error

Import trace for requested module:
./node_modules/@authress/sdk/index.js
./app/api/a/route.ts
./node_modules/next/dist/build/webpack/loaders/next-edge-app-route-loader/index.js?absolutePagePath=[redacted]&page=%2Fapi%2Fa%2Froute&appDirLoader=[redacted]&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D!
 ⨯ ./node_modules/@authress/sdk/src/serviceClientTokenProvider.js:2:28
Module not found: Can't resolve 'crypto'

It looks like serviceClientTokenProvider.js:2:28 is

const { createPrivateKey } = require('crypto');

Not being able to resolve 'crypto' is I think normal for the edge runtime, as it does not include it. More information at cloudflare/next-on-pages#686

I am successfully using jose to retrieve the JWKS details and validating.

Happy to provide any other information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant