【问题标题】:OAuth Authorization in pipeDrive callback using express framework使用 express 框架在 pipeDrive 回调中进行 OAuth 授权
【发布时间】:2018-12-07 18:11:06
【问题描述】:

我在 Marketplace Manager 的 sandbox.pipedrive.com 上创建了一个应用程序,然后我创建了一个回调,要求用户安装我在 pipedrive 中设置的应用程序。

如果用户允许安装,他们会被重定向到我在控制器中的回调 url,我的控制器代码是:-

app.get('/pipedrive-callback', function(req, res) {
    console.log('Success')
});

现在我想在函数中交换身份验证令牌。谁能帮我解决这个问题。

【问题讨论】:

标签: node.js express pipedrive-api


【解决方案1】:

你可以试试这个吗? 用户重定向到您的回调后,您需要向他们的服务器发送另一个发布请求。重定向后,您将从请求参数中获得授权码。您必须在此发布请求中发送该代码才能获得真正的令牌,让您可以施展魔法。

app.get('/pipedrive-callback', function (req, res) {
    console.log('Success');
    const authorization_code_from_service = req.query.code; // This will extract the authorization_code from the call back url.

    //Here goes your step 4 + 5. You need to make a post request to their server now. For this, there is a library aka "request" in npm. 
    // Here is the link for that https://www.npmjs.com/package/request

    const request = require("request");

    const formData = {
        "grant_type": "authorization_code",
        "redirect_uri": "rediect url that you have set for your app",
        "code": authorization_code_from_service
    }


    request.post({
            url: 'https://oauth.pipedrive.com/oauth/token',
            form: formData
        },
        function (err, httpResponse, body) {
            //This will be the data that you need for further steps. Actual token, expiry time etc
            console.log(body);
        }
    );

});

Npm 链接:https://www.npmjs.com/package/request

【讨论】:

  • 感谢兄弟的工作。我还需要将 [client_id] 和 [client_secret] 添加到 formData。
猜你喜欢
  • 1970-01-01
  • 2013-03-14
  • 2015-12-28
  • 2011-04-13
  • 1970-01-01
  • 1970-01-01
  • 2017-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多