Add JWT auth header in the .connect() to the RPC request

Hello! I was hoping someone could give a hand in adding a JWT header authorization in the .connect() method. I was following the quick start and in the chainconfig I can see that you need to specify an RPC. Our RPC (quickNode) needs a JWT in each request, the problem is that we cannot find a way to set the JWT in the request’s header in the .connect() method. Does anyone know how to set a header for the connect request?

What we would like to do is something like this:
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: “0xaa36a7”,
rpcTarget: <OUR_QUICKNODE_RPC>,
displayName: “Ethereum Sepolia Testnet”,
blockExplorerUrl: “https://sepolia.etherscan.io”,
ticker: “ETH”,
tickerName: “Ethereum”,
logo: “https://cryptologos.cc/logos/ethereum-eth-logo.png”,
rpcHeaders: {
‘Authorization’: <OUR_JWT>
}
};

Hi Iván! Thank you for reaching out. It sounds like you’re working on integrating Web3Auth with a QuickNode RPC and need to add a JWT for authorization in the .connect() method.

From your message, I gathered the following details:

  • SDK Details: Plug n Play
  • ChainConfiguration: You’ve shared a sample configuration that seems to be well-structured.
  • Issue: Adding a JWT auth header to the .connect() method.

Unfortunately, the current Web3Auth SDK may not support adding custom headers directly to the .connect() method out-of-the-box. A possible workaround would be to check if you can intercept the request at a different point in your code or look into customizing your HTTP request handling after establishing the connection.

Here’s a proposed solution to consider:

  1. First, connect to the blockchain as you usually would using the .connect() method.
  2. Once the connection is established, use the connected provider to create your own instance of a web3 provider.
  3. Then, when making requests to QuickNode, manually set the JWT header in your HTTP requests.

If you still face issues or if this approach doesn’t meet your needs, it may be helpful to get more specific about your setup, like sharing any error messages you encounter or your current implementation code. Feel free to include any screenshots or code snippets, as they could help the support team assist you better!

Let me know if there’s anything else I can help you with!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Hi Iván! Thank you for reaching out with your query about adding a JWT authorization header in the .connect() method of the Web3Auth SDK.

It seems like you’re working with the Plug n Play SDK and your RPC (QuickNode) requires a JWT token for each request. Currently, the .connect() method doesn’t provide a built-in way to inject headers like JWT directly. However, you can modify your RPC client to include the JWT in the headers after establishing a connection.

Here’s a high-level approach:

  1. Connect using the .connect() method as usual.
  2. After the connection is established, use your custom RPC client to include the JWT in the headers for your requests.

For your reference, here’s how your chainConfig snippet looks:

const chainConfig = {
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  chainId: "0xaa36a7",
  rpcTarget: "OUR_QUICKNODE_RPC",
  displayName: "Ethereum Sepolia Testnet",
  blockExplorerUrl: "https://sepolia.etherscan.io",
  ticker: "ETH",
  tickerName: "Ethereum",
  logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
};

If this approach doesn’t solve the issue, could you please provide the following details:

  • SDK Version Number
  • Platform
  • Any relevant code snippets if available.

This will help us assist you better. Looking forward to your response!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Hi Iván!

Thanks for reaching out! It sounds like you’re working on integrating JWT authentication for your RPC request in the Web3Auth SDK.

To help you better, here’s a summary of your issue for the support team:

  • SDK Details: Help - Plug n Play
  • Issue: Adding JWT authorization header in the .connect() method.
  • Details: You need to send a JWT in the header for your QuickNode RPC during the .connect() method, but there’s no clear way to set headers in that request.

Since you’re trying to connect to your QuickNode with a JWT, it might be helpful to check if there’s a way to extend or customize the connection request to include headers.

I don’t have a direct solution for adding headers in the .connect() method, but I recommend checking the documentation for any mention of custom configuration options or reaching out to the support team for specific guidance.

If you have any code snippets or console errors related to this issue, feel free to share them. They can help the team assist you further.

Let me know if you need anything else!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

I see. This idea of creating a “proxy” to intercept the request and add my custom headers is a possible solution that we had in mind but we were hoping there could be a easier solution. It looks like we are going to try with this method.
If anyone know another possible solution or want to help me in applying an optimized solution for this “proxy”, I would much appreciate the help.
Thank you!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.