Last active
August 29, 2015 14:13
-
-
Save jkresner/8a581e50dcac58edbd10 to your computer and use it in GitHub Desktop.
Node.js Express Login with PayPal Integration (ES6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')(); | |
var pp = require('paypalWrapper'); | |
app.get('/', (req,res,next) => { | |
res.render('index',{paypalLoginUrl:pp.herlpers.getLoginUrl()}); | |
}); | |
app.get('/auth/paypal/callback', pp.handlers.handleAuthCallback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var paypal = require('paypal-rest-sdk') | |
paypal.configure({ | |
'mode': config.auth.paypal.mode, | |
'client_id': config.auth.paypal.clientID, | |
'client_secret': config.auth.paypal.clientSecret, | |
'openid_client_id': config.auth.paypal.clientID, | |
'openid_client_secret': config.auth.paypal.clientSecret, | |
'openid_redirect_uri': `${config.auth.oAuth.callbackHost}/auth/paypal/callback` | |
}); | |
module.exports = { | |
helpers: { | |
getLoginUrl() { | |
//-- you'll have to configure express sessions scope might look like 'openid profile email' | |
return paypal.openIdConnect.authorizeUrl({'scope': config.auth.paypal.scope}); | |
} | |
}, | |
handlers: { | |
handleAuthCallback(req,res,next) { | |
var authCode = req.query.code; | |
var openIdConnect = paypal.openIdConnect; | |
openIdConnect.tokeninfo.create(authCode, function (e, tokeninfo) { | |
if (e) return next(e); | |
paypal.openIdConnect.userinfo.get(tokeninfo.access_token, function (ee, userinfo) { | |
if (e) return next(e); | |
//-- Got it, now do what you need to | |
console.log(tokeninfo); | |
console.log(userinfo); | |
next() | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment