2016-04-08 11 views
2

Mit Passport zu erhalten (von Jared Hanson),Strategie Pass Paypal: failed Zugriffstoken

Wie kann ich Paypal mit OpenID oder OAuth verwenden?

Ich bin mit Pass-paypal-oauth Strategie (https://github.com/jaredhanson/passport-paypal-oauth),

HINWEIS: meine Routen beginnen mit localhost: 4000/api/Benutzer

Meine paypal Endpunkte:

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

Mein Paypal Strategies:

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

Problem: Wenn ich rufe http://localhost:4000/api/users/signin/paypal, ich folgende Antwort im Browser:

[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"}' } } 

Und die function(token, refreshToken, profile, done) { wird nie aufgerufen.

Was ist los?


Ich habe bereits mit http://127.0.0.1:4000/api/users/signin/paypal

statt http://localhost:4000/api/users/signin/paypal

+0

ich das gleiche Problem, ich versuche zu verwenden Pass-paypal, Pass- paypal-op enidconnect und es funktioniert nicht .. – Kael

+0

Nicht sicher, ob es Ihr Problem beheben wird, aber CallbackUrl sollte enthalten http: // localhost: 4000 – Molda

+0

Mit der http: // – Molda

Antwort

1

Ich bin derjenige, der gegabelt und hält das openidconnect Paket

die tokenURL sollte die openidconnect url sein und nicht die oauth2 Token url ...

Sie die tokenURL auslassen kann und authorizationURL und nur Sandbox verwenden: true (I nicht für Pass-paypal sprechen kann, ich habe vergessen, wenn es, dass in zu gebaut hat)

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); 
})); 
+0

BTW nur ​​für den Fall, dass die Leute sich fragen, was die richtige URL ist, sollte openidconnect-Token '/ v1/identity/openidconnect/tokenservice' anstelle von'/v1/oauth2/token' verwenden –

+0

Ich löste dieses Problem mit https: // www. npmjs.com/package/paypal-rest-sdk. –

+0

@ dA3m0n ahh, aber das ist wirklich nicht das Problem mit dem Plugin, es ist teilweise aufgrund der Dokumentation von Paypal, oauth2 URLs scheint nicht mehr zu funktionieren, und openid-connect URLs sind nicht die alten, das Plugin funktioniert solange die richtigen URLs verwendet werden ... –

0

ich nicht getestet, ob es das Problem zu beheben, aber das getan Funktion sollte mit einem wahren Wert in dem Rückruf aufgerufen werden, wenn OK.

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); 
})); 
+0

Diese Funktion wird nie aufgerufen ... es ist das Problem. –