【发布时间】:2021-08-02 07:16:42
【问题描述】:
我正在关注 Coinbase 关于通过 API 向某人发送比特币的指南。 Coinbase 要求用户在调用sendMoney() 时输入 2FA 代码。然后我需要将此代码放在sendMoney() 的HTTP 标头中才能成功执行。但我不确定如何使用 Coinbase 的 API 进行这项工作(sendMoney() 没有用于设置 HTTP 标头的参数)。我想我可以手动 POST 到 URL 而不是调用sendMoney(),但我不确定要传递哪些参数。
function getBalance(client, res){
client.getAccount('BTC', function(err,account){
// SENDING MONEY REQUIRES 2FA
account.sendMoney({
'to': '3MLCRpMDXC3AFBsaSLNimWfJFvsMVBq4Ac',
'amount': '0.0000018',
'currency': 'BTC'
}, function(err, txt){
res.render('authPurchase'); // RENDER INPUT FIELD FOR USER TO ENTER 2FA CODE
});
});
} // how do I 'replay' the above sendMoney request with the 2FA code in the http header?
Coinbase Docs 提供了此演练,但遗憾的是没有关于使用 2FA 授权发出 POST 请求的示例。
1. User is sending funds and the app calls POST api.coinbase.com/v2/accounts/primary/transactions
2. Server responds with 402 and sends the user a 2FA token via SMS if he doesn’t have Authy installed
3. App re-plays the request from step 1 with exactly same parameters and the 2FA token in the CB-2FA-TOKEN header (HOW????)
4. Transaction is sent and 201 CREATED status code is returned
【问题讨论】:
标签: javascript node.js coinbase-api