Error: A redirection handler must be provided in the Node environment

I am (still) trying to make sense of the authentication flow that using statically registered client credentials.

I know that the piece of code that I’m using is working in an isolated environment. However when running in an electron app, I see the following error, that I cannot make sense of:

Uncaught (in promise) Error: A redirection handler must be provided in the Node environment.
    at Redirector.redirect (plugin:obsidian-solid-plugin:10973:17)
    at AuthorizationCodeWithPkceOidcHandler.handle (plugin:obsidian-solid-plugin:10599:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ClientAuthentication.login (plugin:obsidian-solid-plugin:5713:31)
    at async Session2.login (plugin:obsidian-solid-plugin:11262:29)
    at async podLoginHandler (plugin:obsidian-solid-plugin:43108:7

What should this redirection handler be?

The code in question can be found here.

The Inrupt SDKs do not officially support electron or react-native at this point. That error is talking about the redirect handler found in this documentation, however, it should apply here as you’re not doing a multi-session setup, and instead doing single user.

https://docs.inrupt.com/developer-tools/javascript/client-libraries/tutorial/authenticate-nodejs-web-server/

Most likely, the values passed as clientId and clientSecret are undefined or incorrectly passed, causing the code to fall through to how it behaves with redirect based flows. Alternatively, clientType not of static will also have this effect.

Thanks! Although, I don’t understand why would electron or react-native not be supported TBH: aren’t the SDKs based on HTTP?

I got one step further, as it looks that indeed the values weren’t properly passed from my input form, but now bumping into another cryptic message:

Uncaught (in promise) TypeError: The "key.key" property must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView. Received undefined
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at new NodeError (node:internal/errors:371:5)
    at prepareAsymmetricKey (node:internal/crypto/keys:528:13)
    at Object.createPrivateKey (node:internal/crypto/keys:602:5)
    at Client.dpopProof (plugin:obsidian-solid-plugin:10021:30)
    at Client.value (plugin:obsidian-solid-plugin:10064:21)
    at Client.request (plugin:obsidian-solid-plugin:7056:40)
    at Client.authenticatedPost (plugin:obsidian-solid-plugin:7578:22)
    at async Client.grant (plugin:obsidian-solid-plugin:9728:26)
    at async ClientCredentialsOidcHandler.handle (plugin:obsidian-solid-plugin:11147:24)
    at async ClientAuthentication.login (plugin:obsidian-solid-plugin:5713:31)
    at async Session2.login (plugin:obsidian-solid-plugin:11262:29)
    at async podLoginHandler (plugin:obsidian-solid-plugin:43108:7)

It does look like something is preventing things from working properly in electron… Again, why would that be the case?

Because Electron & React-Native have different APIs for cryptography, data storage, security, etc. They also require specialized testing setups to ensure compatibility.

I can’t really assist in debugging this, but if I were to have to debug it, I’d be setting a breakpoint at dpopProof and stepping through the code from there. Most likely something is resulting in the keypair used in dpop proof calculation from not being valid/correct.

OK that makes sense. I was thinking that cryptography and security etc would have been abstracted away, or that electron would not be that different to node but… not the case, alright.

However, this sounds like the end of my little experiment. I don’t have time to debug at such a low level either.

Thank you for all your support. Long live Solid!