BlueWallet / LndHub

Wrapper for Lightning Network Daemon. It provides separate accounts for end-users
http://LndHub.io
MIT License
752 stars 185 forks source link

API auth /getinfo 404 error #300

Closed MG-ng closed 2 years ago

MG-ng commented 2 years ago

Hi, I have a question about communicating with LndHub using python requests. I think I don't get the authorization correctly.

First I type import requests then

r1 = requests.post( "http://<localip>:3000/create", headers={ 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json' } )

which works well and then

r2 = requests.post( "http://<localip>:3000/auth?type=auth", headers={ 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json' }, json={ 'login': '<loginFromPreviousResponse>', 'password': '<passFromPreviousResponse>' })

which also works fine and delivers with r2.json() a refresh_token and an access_token.

r3 = requests.post( "http://<localip>:3000/getinfo", headers={ 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json', 'Authorization': 'Bearer <access_tokenFromPreviousResponse>' } )

But if I do now a r3.json() or a r3.content it prints 404 or b'404'.

I don't know what I'm doing wrong :/

I looked at the BlueWallet code and translated this param to a header field https://github.com/BlueWallet/BlueWallet/blob/13708383437d3c66ea536250e46c88138e9827d0/class/wallets/lightning-custodian-wallet.js#L565

I tried to send the same as the BlueWallet app but somehow it don't work. The log also just prints a 404:

Sep 25 16:34:02 raspi node[8076]: 97f165cf-b936-48ab-b944-a838a4b8d71c <sendingDeviceIP> - - [25/Sep/2021:14:34:02 +0000] "POST /info HTTP/1.1" 404 3 "-" "python-requests/2.25.1"

Thank you for your help!

Overtorment commented 2 years ago

sorry cant help here, i wrote this like 3 years ago and totally don't remember how it works under the hood. but other people create their own API clients (like lnbits, you could look there), and everything works

MG-ng commented 2 years ago

Turns out it was just me using .post() instead of .get() despite the docs saying clearly that you should use get on the getinfo function 😅

Thank you very much! LNbits is very interesting (but server side) and during the search for other python clients I found the solution here