使用PayPal REST SDK(Node JS)无法生成用户信息

时间:2018-12-19 13:56:44

标签: node.js angular paypal paypal-sandbox

使用自定义贝宝登录按钮(https://developer.paypal.com/docs/integration/direct/identity/button-js-builder/),我将访问已登录用户的授权代码。使用该授权码,我想获取用户信息,例如电子邮件地址,名字和姓氏。使用GitHub存储库作为参考。

GitHub存储库-https://github.com/nishit321/PayPalIdentityNode

问题-我无法使用授权码(通过使用PayPal登录按钮生成)获取用户信息(电子邮件,名字等)。按照下面的代码,我只会得到user_id。

var paypal = require('paypal-rest-sdk');
var openIdConnect = paypal.openIdConnect;
paypal.configure({
    'mode': 'sandbox', //sandbox or live
    'openid_client_id': 'xxx',
    'openid_client_secret': 'xxxx',
    'openid_redirect_uri' : 'http://localhost:4200/paypal-identity'
});
console.log(openIdConnect.authorizeUrl({'scope': 'openid profile'}));
// With Authorizatiion code
openIdConnect.tokeninfo.create('auth-code-here', function (error, tokeninfo) {
    if (error) {
        console.log(error);
    } else {
        openIdConnect.userinfo.get(tokeninfo.access_token, function (error, userinfo) {
            if (error) {
                console.log(error);
            } else {
                console.log(tokeninfo);
                console.log(userinfo);

                // Logout url
                //console.log(openIdConnect.logoutUrl({ 'id_token': tokeninfo.id_token }));
            }
        });
    }
});

以上代码响应如下-

{ token_type: 'Bearer',
  expires_in: '28800',
  refresh_token: 'xxx',
  id_token: 'xxx',
  access_token: 'xxx',
  httpStatusCode: 200 }
{ user_id: 'https://www.paypal.com/webapps/auth/identity/user/xxxx',
  httpStatusCode: 200 }

0 个答案:

没有答案