You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We would like to use this KnownUser library for server-side queueing from a Next.js application, but we are finding the Node library difficult to apply to our use-case.
The main problem we have is the requirement that context provider (IConnectorContextProvider) functions all return synchronous results instead of async/promises, especially getCryptoProvider().getSha256Hash().
We want to run the KnownUser validation in Next.js middleware but in these run in an Edge Runtime context where we don't have access to native Node libraries like crypto as used in the example. Instead we can use the Web Crypto API, but that only provides async crypto functions.
This means we cannot generate a HMAC/SHA-256 hash value for getCryptoProvider().getSha256Hash() synchronously, only with an async result which doesn't work where this context function is called in the rest of the codebase.
We are attempting to work around this by implementing just the incompatible pieces of KnownUser in own code – specifically token validation and follow-on cookie-setting – but are finding that the relatively few functions & utils exposed by KnownUser is making this difficult without re-implementing much of the library.
If the KnownUser library could support async function implementations in the context provider it would most likely work for us out of the box.
The text was updated successfully, but these errors were encountered:
Hi,
We are looking at the async support but do not have any timing for it.
As a workaround, you can bundle any sha256 library inside the javascript locally (without using the native module)
Please feel free to contact our support team we are happy to arrange a call and discuss the solution.
For anyone following, here's the final implementation I ended up with for Next.js middleware:
// Install `crypto-js` and add these imports:// import Hex from "crypto-js/enc-hex";// import hmacSHA256 from "crypto-js/hmac-sha256";getCryptoProvider: function(){return{getSha256Hash: function(secretKey,plaintext){// NOTE: We must use `crypt-js` library here instead of Node's// `crypto` built-in library, or other options like `js-sha256`,// because the other options rely on Node.js library inclusions that// aren't present or don't work in the Edge Runtime environmentconsthash=hmacSHA256(plaintext,secretKey);consthexHash=Hex.stringify(hash);returnhexHash;},};},
We would like to use this KnownUser library for server-side queueing from a Next.js application, but we are finding the Node library difficult to apply to our use-case.
The main problem we have is the requirement that context provider (
IConnectorContextProvider
) functions all return synchronous results instead of async/promises, especiallygetCryptoProvider().getSha256Hash()
.We want to run the
KnownUser
validation in Next.js middleware but in these run in an Edge Runtime context where we don't have access to native Node libraries likecrypto
as used in the example. Instead we can use the Web Crypto API, but that only provides async crypto functions.This means we cannot generate a HMAC/SHA-256 hash value for
getCryptoProvider().getSha256Hash()
synchronously, only with an async result which doesn't work where this context function is called in the rest of the codebase.We are attempting to work around this by implementing just the incompatible pieces of KnownUser in own code – specifically token validation and follow-on cookie-setting – but are finding that the relatively few functions & utils exposed by KnownUser is making this difficult without re-implementing much of the library.
If the KnownUser library could support async function implementations in the context provider it would most likely work for us out of the box.
The text was updated successfully, but these errors were encountered: