deno_std: Not implemented: crypto.Hmac error with Jsonwebtoken
Describe the bug
I am trying to use jsonwebtoken with Deno’s compatibility mode, but I am seeing the following error:
Uncaught Error: Not implemented: crypto.Hmac
Steps to Reproduce
With the following webtoken.mjs file:
import jwt from 'jsonwebtoken'
const token = jwt.sign({ foo: 'bar' }, 'shhhhh');
console.log(token);
deno run
(in compat mode) fails as follows:
% deno run --unstable --allow-env --allow-read --compat webtoken.mjs
error: Uncaught Error: Not implemented: crypto.Hmac
throw new Error(message);
^
at notImplemented (https://deno.land/std@0.152.0/node/_utils.ts:23:9)
at new Hmac (https://deno.land/std@0.152.0/node/internal/crypto/hash.ts:136:5)
at Object.createHmac (https://deno.land/std@0.152.0/node/crypto.ts:264:10)
at Object.sign (file:///Users/penberg/src/chiselstrike/webtoken/node_modules/jwa/index.js:132:23)
at Object.jwsSign [as sign] (file:///Users/penberg/src/chiselstrike/webtoken/node_modules/jws/lib/sign-stream.js:32:24)
at Object.module.exports [as sign] (file:///Users/penberg/src/chiselstrike/webtoken/node_modules/jsonwebtoken/sign.js:204:16)
at file:///Users/penberg/src/chiselstrike/webtoken/webtoken.mjs:3:19
Expected behavior
% node webtoken.mjs
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE2NjEzMzIwOTR9.dmuExDy4XoLwze8PDox3xRH7UCRklkFbrbhLLXIaNrQ
Environment
- OS: MacOS 12.4
- deno version: 1.24.3
- std version: 0.152.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 22 (4 by maintainers)
I’m getting error:
Uncaught Error: Not implemented: crypto.Sign
when trying to use Google APIs with NPM Specifiers. Is there a suggested work around for this in the meantime or should I trundle back to Node?closed by #2664
Looks like there’s some more unimplemented bits. As pointed out by @ricardodalarme, Octokit seems to use
jsonwebtoken
withRS256
algorith, which hits a different unimplemented path incrypto
:Not sure if this is of any help to anyone but I wrote a module that gets Google auth tokens and now I just use Google’s REST apis/endpoints directly rather than using and relying on the googleapis package. Use it everyday for work.
@gabobaxx @elekram Any solution found to solve this issue when trying to use with the
googleapis
?For people stumbling here and using esm.sh to get JSON Web Token into deno; I had to force esm to use deno-std@0.166.0 via
import jwt from "https://esm.sh/jsonwebtoken@8.5.1?deno-std=0.166.0”;
, else it defaults to 0.165.0googleapis seems to depend on gRPC, which is not yet supported in Deno, although it seems that it is being worked on https://github.com/denoland/deno/issues/3326#issuecomment-1198729530.
For the REST APIs, you may want to try the browser version: https://github.com/google/google-api-javascript-client
@penberg alright! I’ll take a look at it too, the HMAC implementation is kinda done, but there are still some tests missing and the type checking is not right too. I guess that I can take a look this Sunday
The Standard Library no longer contains the implementation for the Node compatibility layer. If you’re still having issues, please see the repo for the Deno CLI.
I’ll give this a crack.
Maybe worth mentioning: This is also blocking npm AWS SDK usage. I wonder if there’s any way to polyfill this with something like
npm:node-forge
in the meantime?Hey! I’m trying to implement an application that use the google api method but i’m getting this error:
This is the code:
I ran this same code in nodejs and it’s worked well. More info:
@ricardodalarme yep! I have made some progress on the PR, the tests are the only thing missing, I’ll do them probably this weekend
I’m taking a stab at this one!