-
-
Notifications
You must be signed in to change notification settings - Fork 326
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
Bun bun bun!! #579
Comments
Because bun is Web Platform API first and node's crypto module compatibility is not guaranteed and will never be a 100%. |
There isn't anything wrong with jwks-rsa, but it's a node module, not one made for other runtimes. |
Mention it on docs. Please? |
jwks-rsa has a package.json engines entry marking it node-only. |
BTW, the crypto works fine if I point bun to the node package of jose. |
It might for you, it might not for others. Open an issue with bun on how they resolve node-first module dependencies. Yours is not an isolated issue, i've seen them popping up and it's a runtime issue. |
FYI auth0/node-jwks-rsa#374 give this branch a shot and let me know if there's anything else. |
Hey @panva its me again. Here is my code. import JwksClient from "jwks-rsa";
import JsonWebToken, { JwtHeader } from "jsonwebtoken";
const client = JwksClient({
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
})
const keySets: any = await client.getKeys();
export const certToPEM = (cert: string) => {
cert = cert.match(/.{1,64}/g)!.join('\n')
cert = `-----BEGIN CERTIFICATE-----\n${cert}\n-----END CERTIFICATE-----\n`;
return cert;
}
export const verifySession = (token: string) => {
const decoded = JsonWebToken.decode(token, { complete: true }) as { header: JwtHeader, payload: any };
const kid = decoded.header.kid;
const keySet = keySets.find((key: { kid: string; }) => key.kid === kid);
if (!keySet) {
throw new Error("No key set");
}
const signingKey = certToPEM(keySet.x5c[0]);
return JsonWebToken.verify(token, signingKey);
} Here is my error
|
https://bun.sh/docs/runtime/nodejs-apis#node-crypto Bun does not implement those APIs. Use jose, not jsonwebtoken. You can replace both jwks-rsa and jsonwebtoken with jose. const JWKS = jose.createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'))
const { payload, protectedHeader } = await jose.jwtVerify(jwt, JWKS, {
issuer: 'urn:example:issuer',
audience: 'urn:example:audience',
})
console.log(protectedHeader)
console.log(payload) |
This was the code that got me segmentation fault |
Then create a reproduction sample and open a Bun issue please, there's nothing I can do about those. |
Sure man, thx you for helping me out. |
To explain, it is far more likely the segmentation fault is related to some other code and just presents itself when the jose code yields control. So it seems like jose is triggering it but it's not. The whole jose test suite gets executed using Bun without segmentation faults. |
Hmm I am using Auth0 to do openid stuff. My JWKS does not contain publicKey directly. I use x5c to create it. Can this be the reason? PS: Also the jwks-rsa is your custom branch from github not from npm |
The OP is correct. Every thing is fine in node |
JWKs are the public keys, just in a JWK format |
Ohhh got |
What happened?
Duuddee!
Why import bun as a browser module?
jose/package.json
Line 80 in 22c05ce
I am using bun on the server because it's so sexy with typescript.
I wasted 2 hours thinking something was wrong with
jwks-rsa
auth0/node-jwks-rsa#373Version
doesnt matter!
Runtime
Other (I will specify below)
Runtime Details
bun bun bun
Code to reproduce
https://github.com/panva/jose/blob/22c05ceeaecb850c6933d4ef5bc0935a8acf6854/package.json#L80
Required
The text was updated successfully, but these errors were encountered: