使用策略护照paypal:无法获取访问令牌

时间:2016-04-08 11:01:14

标签: node.js paypal oauth passport.js

使用Passport(Jared Hanson),

如何在openID或OAuth中使用Paypal?

我正在使用passport-paypal-oauth策略(https://github.com/jaredhanson/passport-paypal-oauth),

注意:我的路线以localhost:4000 / api / users

开头

我的paypal端点:

var passport_paypal = require('../middlewares/passport-paypal');

router.get('/signin/paypal', passport_paypal.authenticate('paypal-signin', {
scope: 'openid profile email'}));

router.get('/signin/paypal/callback', function(req, res, next){
passport_paypal.authenticate('paypal-signin', function(err, user, info){
    // Handle cases
    //return res.status(xxx).json('.. 
});

我的Paypal策略:

var PaypalStrategy = require('passport-paypal-oauth').Strategy;

passport.use('paypal-signin', new PaypalStrategy({
clientID         : "MY APP ID",
clientSecret     : "MY APP SECRET",
callbackURL      : "http://localhost:4000/api/users/signin/paypal/callback",
tokenURL         : "https://api.sandbox.paypal.com/v1/oauth2/token",
authorizationURL : "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize"

}, function(token, refreshToken, profile, done) {

    !!!!! Not called ...

    // Get user profie
   // Save in db or other handling
}));

问题:当我致电http://localhost:4000/api/users/signin/paypal时,   我在浏览器中得到以下答案:

 [InternalOAuthError: failed to obtain access token]
 name: 'InternalOAuthError',
 message: 'failed to obtain access token',
 oauthError:
 { statusCode: 400,
 data: '{"error":"invalid_client","error_description":"Client credentials are missing"}' } }

永远不会调用function(token, refreshToken, profile, done) {

有什么问题?

我已经使用http://127.0.0.1:4000/api/users/signin/paypal

进行了测试

而不是http://localhost:4000/api/users/signin/paypal

2 个答案:

答案 0 :(得分:1)

我是分叉并维护openid-connect包的人

tokenURL应该是openidconnect网址而不是oauth2令牌网址...

你可以省略tokenURL和authorizationURL,只使用sandbox:true(我不能代表护照 - paypal,我忘了它是否内置了)

passport.use('paypal-signin', new PaypalStrategy({
  clientID         : "MY APP ID",
  clientSecret     : "MY APP SECRET",
  callbackURL      : "http://localhost:4000/api/users/signin/paypal/callback",
  sandbox: true
}, function(token, refreshToken, profile, done) {
  // Get user profie
  // Save in db or other handling
  done(true);
}));

答案 1 :(得分:0)

我不知道它是否能解决问题,但是如果没问题,应该在回调中调用done函数并使用true值。

passport.use('paypal-signin', new PaypalStrategy({
clientID         : "MY APP ID",
clientSecret     : "MY APP SECRET",
callbackURL      : "http://localhost:4000/api/users/signin/paypal/callback",
tokenURL         : "https://api.sandbox.paypal.com/v1/oauth2/token",
authorizationURL :   "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize"

 }, function(token, refreshToken, profile, done) {
  // Get user profie
  // Save in db or other handling
  done(true);
 }));