为并行请求生成 oAuth nonce [英] Generate oAuth nonce for parallel requests

查看:43
本文介绍了为并行请求生成 oAuth nonce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在并行请求 Bitstamp API:

I am requesting Bitstamp API in parrallel:

// Simplified version

var async = require('async');
var bitstamp = require('bitstamp');

async.parallel([
    bitstamp.balance,
    bitstamp.ticker
    // ...
],
function() (err, result) {
    // process results
});

这两种方法正在向 Bitstamp API 发送签名请求,包括 nonce.

Those two methods are sending signed requests to Bitstamp API including nonce.

Nonce 是一个常规整数.它必须随着您提出的每个请求而增加.在此处阅读更多相关信息.示例:如果您在第一个请求中将 nonce 设置为 1,则必须在第二个请求中将其设置为至少 2.您不需要从 1 开始.通常的做法是对该参数使用 unix 时间.

Nonce is a regular integer number. It must be increasing with every request you make. Read more about it here. Example: if you set nonce to 1 in your first request, you must set it to at least 2 in your second request. You are not required to start with 1. A common practice is to use unix time for that parameter.

底层库以传统方式生成随机数:

Underlying library generates nonce traditional way:

var nonce = new Date().getTime() + '' + new Date().getMilliseconds();

问题

由于异步 API 调用,有时 nonce 生成它的毫秒数非常相同,而远程端希望它们增加.

Problem

Because of asynchronous API calls, sometimes nonce generated it very same millisecond, while remote side wants them increasing.

保持并行请求,有没有办法可靠地生成顺序随机数?

Keeping parallel requests, any idea to reliably generate sequential nonce?

我明显的尝试:

this.nonce = new Date().getTime() + '' + new Date().getMilliseconds(); 
// ... on request
var nonce = this.nonce++;

但这并没有解决问题,同样的毫秒只是增加了1,但仍然相等.

But it doesn't solve the problem, same millisecond just increased by one, but still equal.

推荐答案

npm nonce 模块现在可以正确生成它

npm nonce module is now generate it correctly

这篇关于为并行请求生成 oAuth nonce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆