使用策略护照贝宝:无法获取访问令牌
Using strategy passport paypal : failed to obtain access token
有护照(贾里德·汉森),
如何通过 openID 或 OAuth 使用 Paypal?
我正在使用 passport-paypal-oauth 策略 (https://github.com/jaredhanson/passport-paypal-oauth),
注意: 我的路线以 localhost:4000/api/users
开头
我的贝宝端点:
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) {
从未被调用。
怎么了?
测试过
不知道能不能解决问题,如果没问题,应该在回调中调用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);
}));
我是 openid-connect 包的 fork 和维护者
tokenURL 应该是 openidconnect url 而不是 oauth2 令牌 url...
你可以省略 tokenURL 和 authorizationURL,只使用 sandbox: true (我不能代表 passport-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);
}));
有护照(贾里德·汉森),
如何通过 openID 或 OAuth 使用 Paypal?
我正在使用 passport-paypal-oauth 策略 (https://github.com/jaredhanson/passport-paypal-oauth),
注意: 我的路线以 localhost:4000/api/users
开头我的贝宝端点:
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) {
从未被调用。
怎么了?
测试过
不知道能不能解决问题,如果没问题,应该在回调中调用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);
}));
我是 openid-connect 包的 fork 和维护者
tokenURL 应该是 openidconnect url 而不是 oauth2 令牌 url...
你可以省略 tokenURL 和 authorizationURL,只使用 sandbox: true (我不能代表 passport-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);
}));