stjet / bananopie

A python library for Banano. Not just a RPC wrapper!
https://pypi.org/project/bananopie/
MIT License
16 stars 2 forks source link

Allow custom Authorization Headers in RPC #3

Open elementalennui-dev opened 1 month ago

elementalennui-dev commented 1 month ago

Hi @stjet!

I've been poking around with using the NanSwap Banano Node as an RPC due to it's ability to generate work. However, it requires a custom Auth header of {"nodes-api-key": NODES_API_KEY}.

It looks like in RPC.py, this code block exists:

headers = {}
#add auth header, if exists
if self.auth:
   headers['Authorization'] = self.auth
resp = requests.post(self.rpc_url, json=payload, headers=headers)

Which allows common auth headers like Bearer and JWT Tokens.

To get the NanSwap node to work, it looks like I need to submit a request with a custom header key, not Authorization.

The nano.js code has a parameter called customHeaders which allows custom key/val pairs to be set for auth headers. It would be great to have similar functionality here. Let me know your thoughts!

stjet commented 1 month ago

Not against adding option for custom headers, but seems like Nanswap API allows the API key as a url query param now. (eg: https://nodes.nanswap.com/BAN?api_key=YOUR_API_KEY)