用于OAuth2访问令牌生成的节点模块?

时间:2016-03-04 12:33:53

标签: node.js oauth-2.0

我正在使用Node.js,其中我使用 superagent 来调用oauth令牌生成请求,我手动解析一个响应,我从中提取access_token,refresh_token,token_type,expires_in等

下面的

是通过superagent call

生成oauth令牌的片段
superagent
    .post('https://myapi.com/oauth_token.do')
    .proxy(proxy)
    .type('form')
    .send({grant_type: 'password' })
    .send({client_id: 'client-id-value' })
    .send({client_secret: 'client-secreat-value' })
    .send({username: 'user' })
    .send({password: 'pass' })
    .set('Accept', 'application/json')
    .end(function(err, res){
    if (err || !res.ok) {           
        // error handling..
    } else {
        // response parsing..
    }); 


我正在寻找node.js模块,它将负责生成oauth令牌。是否有任何节点js模块相同?
如果可能的话,请您分享样本。

感谢。

2 个答案:

答案 0 :(得分:0)

对于令牌生成,您可以尝试以下任一方式:

rand-tokennode-hat

答案 1 :(得分:0)

auth0 提供了很好的库。在节点中,我使用 jsonwebtoken。如果您向下滚动 https://jwt.io/ 页面,它们会列出大量库和功能。

这是使用他们的库签署 JWT 的样子。

import jwt from "jsonwebtoken";

// setup...

const token = jwt.sign(oPayload, bufferPrivateKey, 
  { algorithm: 'ES256',
    issuer: 'ME-MYSELF-I',
    expiresIn: '30 days'
  });