生成并行请求的oAuth随机数 [英] Generate oAuth nonce for parallel requests

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

问题描述

我正在并行请求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是一个正整数.随着您提出的每个请求,它必定会增加.在这里阅读更多有关它的信息.示例:如果在第一个请求中将现时设置为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++;

但这并不能解决问题,同一毫秒仅增加了一个,但仍然相等.

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随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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