【问题标题】:Node module for OAuth2 Access Token generation?用于 OAuth2 访问令牌生成的节点模块?
【发布时间】:2016-06-18 04:44:18
【问题描述】:

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

以下是通过 superagent 调用生成 oauth 令牌的 sn-p

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..
    }); 


我正在寻找负责生成 oauth 令牌的 node.js 模块。是否有相同的节点 js 模块?
如果可能的话,请您也分享一下示例。

谢谢。

【问题讨论】:

    标签: node.js oauth-2.0


    【解决方案1】:

    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'
      });
    

    【讨论】:

      【解决方案2】:

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

      rand-tokennode-hat

      【讨论】:

      • 感谢您的回复,但我想通过 REST API 生成令牌。
      猜你喜欢
      • 2014-01-25
      • 2015-09-28
      • 2016-07-22
      • 2020-09-21
      • 2014-05-19
      • 2020-02-09
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      相关资源
      最近更新 更多