btcpayserver/node-btcpay

Cannot get token

hazratgs opened this issue · 6 comments

guys trying to get a token, doing everything according to the instructions, but does not work (at the end of an error 403

Is the instruction really working?

what do you mean 'at the end'? when you do create invoice?

@hazratgs Could you also share what statements you are invoking to get to the point of getting a 403 error?

@hazratgs Could you also share what statements you are invoking to get to the point of getting a 403 error?

The guys when I try to create an invoice, I constantly have a 401 error, although I do everything according to the instructions:

info: BTCPayServer.Security.BitpayAuthentication+BitpayAuthHandler: Bitpay.Auth was not authenticated. Failure message: Invalid credentials
info: BTCPayServer.Security.BitpayAuthentication+BitpayAuthHandler: AuthenticationScheme: Bitpay.Auth was challenged.

perform the following steps:

  • create a private key
  • I get clientId using it (that is, I get SIN)
  • I create a new token in the admin panel btcpayserver-> stores-> Access token
  • copying the pairing code and sending a request to /tokens, the request looks like this: body {pairingCode: 'j6jfkaf', id: 'Tf3WxtCNvPR9ATBjc14Wrw6EBxBS5AWn8Li'}
  • in response, I successfully receive the token
  • then I create an invoice {price: 900, currency: 'USD', token: '****'}
  • add X-Identity and X-Signature headers
{
'X-Identity': Buffer.from(this.keypar.getPublic().EncodeCompressed()).ToString('hex'),
'X-Signature': this.sign(url, this.keypar).toString ('hex')
}

where url is host + uri + payload, and payload is JSON request body

After that, I successfully create an invoice, everything works!
But after all, the current token will become obsolete after some time, and I added functionality to update it for example after 10 hours.

I save the private key to a file:

fs.writeFile('./key', JSON.stringify(keys.priv), 'utf-8', (err) => {
  if (err) console.log('err generateKeys:', err)
})

Then, when restarting the service, I load the private key:

const file = fs.readFileSync('./key', 'utf8')
this.keypar = ec.keyFromPrivate(Buffer.from(JSON.parse(file), 'hex'))

To get a new token, I send a request to / tokens with the following parameters

{
  label: 'label', // obtained by pairing pair code
  id: 'Tf3WxtCNvPR9ATBjc14Wrw6EBxBS5AWn8Li',
  facade: 'merchant'
}

In response, I get a new token and using it I try to create an invoice, but I get the error 401 (

Guys, explain to me how to organize work with the API?

Regarding your library, the instruction for creating a key is ridiculous, how to save a BN object in an ENV? I did everything as in your instructions and I can even record a video, it does not work

I want to know, after pairing paircode, I can use the received data to create a new token, right? but it does not work (

The source code for my implementation is here: https://github.com/hazratgs/btcpay-node/blob/master/payqr.js

@hazratgs not sure if this is still an issue (considering how long it has been) but if it still is, can you give the list of steps you took to the point where you are unable to get a token?

@takinbo some time later but I struggle with the same issue.

As BTCPAY_KEY I use the key generated in first step Private key generation. Hope it's correct.

Error from BtcPay:
info: BTCPayServer.Security.Bitpay.BitpayAuthenticationHandler: Bitpay was not authenticated. Failure message: BitId authentication failed
info: BTCPayServer.Security.Bitpay.BitpayAuthenticationHandler: AuthenticationScheme: Bitpay was challenged.

Error in script: StatusCodeError: 401 - undefined
What's funny that the post calling script (console.log) shows me that the payload body is
'{"price":20,"currency":"USD","token":"3ySSfoS3Zbiza1ARycUrNA473xUvRdajctnX9xoruJ1b"}' and token matches the one visible in BtcPay.

Tested on Node: 11.15.0 and 14.2.0

EDIT: Issue is fixed. My url was BTCPAY_URL='http://localhost:80' and issue was fixed after changing it to BTCPAY_URL='http://localhost/;

Good to know 🚀