【问题标题】:How to Resend HTTP Request With 2FA Code?如何使用 2FA 代码重新发送 HTTP 请求?
【发布时间】: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


    【解决方案1】:

    我想通了!

    module.exports.replaySendMoney = function replaySendMoney(smsCode){
        // in the future access token will be stored and retrieved from database
        var Client = require('coinbase').Client;
        let accessToken = '2aac7a723eb58bfaf13a9073ac7b6982dca072f14fa0abbc766e9ed9f60be596';
        let refreshToken = '17a609e13c7608ecd499a1be502da19a7095ccf2d5fe9f40fca2b87501f7c233';
        var client = new Client({'accessToken': accessToken, 'refreshToken': refreshToken});
        client.getAccount('BTC', function(err,acct){
                    // REQUIRES 2FA
            acct.sendMoney({
                'to': '3MLCRpMDoC3AFBsbSLNimWfJFvsMVBq4Ac',
                'amount': '0.0000018',
                'currency': 'BTC',
                'two_factor_token' : smsCode
            }, function(err, txt){
                console.log(err);
                console.log(txt);
                res.render('authPurchase', {});
            });
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 2015-12-08
      • 2020-10-31
      • 2020-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多