diff --git a/config/env/development.js b/config/env/development.js index 31018945..c61be6e5 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -29,6 +29,12 @@ module.exports = { clientID: process.env.GITHUB_ID || 'APP_ID', clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET', callbackURL: '/api/auth/github/callback' + }, + paypal: { + clientID: process.env.PAYPAL_ID || 'CLIENT_ID', + clientSecret: process.env.PAYPAL_SECRET || 'CLIENT_SECRET', + callbackURL: '/api/auth/paypal/callback', + sandbox: true }, mailer: { from: process.env.MAILER_FROM || 'MAILER_FROM', diff --git a/config/env/production.js b/config/env/production.js index 01cc6beb..003be5fe 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -27,6 +27,12 @@ module.exports = { clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET', callbackURL: '/api/auth/github/callback' }, + paypal: { + clientID: process.env.PAYPAL_ID || 'CLIENT_ID', + clientSecret: process.env.PAYPAL_SECRET || 'CLIENT_SECRET', + callbackURL: '/api/auth/paypal/callback', + sandbox: false + }, mailer: { from: process.env.MAILER_FROM || 'MAILER_FROM', options: { diff --git a/config/env/test.js b/config/env/test.js index dd0c6184..9a6d9514 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -31,6 +31,12 @@ module.exports = { clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET', callbackURL: '/api/auth/github/callback' }, + paypal: { + clientID: process.env.PAYPAL_ID || 'CLIENT_ID', + clientSecret: process.env.PAYPAL_SECRET || 'CLIENT_SECRET', + callbackURL: '/api/auth/paypal/callback', + sandbox: true + }, mailer: { from: process.env.MAILER_FROM || 'MAILER_FROM', options: { diff --git a/modules/users/client/img/buttons/paypal.png b/modules/users/client/img/buttons/paypal.png new file mode 100644 index 00000000..54689395 Binary files /dev/null and b/modules/users/client/img/buttons/paypal.png differ diff --git a/modules/users/client/views/authentication/authentication.client.view.html b/modules/users/client/views/authentication/authentication.client.view.html index 3f67964d..b5e422ea 100644 --- a/modules/users/client/views/authentication/authentication.client.view.html +++ b/modules/users/client/views/authentication/authentication.client.view.html @@ -16,6 +16,9 @@ + + +
diff --git a/modules/users/client/views/settings/manage-social-accounts.client.view.html b/modules/users/client/views/settings/manage-social-accounts.client.view.html index b40b203e..6a0b4730 100644 --- a/modules/users/client/views/settings/manage-social-accounts.client.view.html +++ b/modules/users/client/views/settings/manage-social-accounts.client.view.html @@ -40,5 +40,11 @@ +
+ + + + +
diff --git a/modules/users/server/config/strategies/paypal.js b/modules/users/server/config/strategies/paypal.js new file mode 100644 index 00000000..21271bf9 --- /dev/null +++ b/modules/users/server/config/strategies/paypal.js @@ -0,0 +1,42 @@ +'use strict'; + +/** + * Module dependencies. + */ +var passport = require('passport'), + PayPalStrategy = require('passport-paypal-openidconnect').Strategy, + users = require('../../controllers/users.server.controller'); + +module.exports = function (config) { + passport.use(new PayPalStrategy({ + clientID: config.paypal.clientID, + clientSecret: config.paypal.clientSecret, + callbackURL: config.paypal.callbackURL, + scope: 'openid profile email', + sandbox: config.paypal.sandbox, + passReqToCallback: true + + }, + function(req, accessToken, refreshToken, profile, done) { + // Set the provider data and include tokens + var providerData = profile._json; + providerData.accessToken = accessToken; + providerData.refreshToken = refreshToken; + + // Create the user OAuth profile + var providerUserProfile = { + firstName: profile.name.givenName, + lastName: profile.name.familyName, + displayName: profile.displayName, + email: profile._json.email, + username: profile.username, + provider: 'paypal', + providerIdentifierField: 'user_id', + providerData: providerData + }; + + // Save the user OAuth profile + users.saveOAuthUserProfile(req, providerUserProfile, done); + } + )); +}; diff --git a/modules/users/server/routes/auth.server.routes.js b/modules/users/server/routes/auth.server.routes.js index 6390beed..02b64718 100644 --- a/modules/users/server/routes/auth.server.routes.js +++ b/modules/users/server/routes/auth.server.routes.js @@ -50,4 +50,8 @@ module.exports = function(app) { // Setting the github oauth routes app.route('/api/auth/github').get(passport.authenticate('github')); app.route('/api/auth/github/callback').get(users.oauthCallback('github')); + + // Setting the paypal oauth routes + app.route('/api/auth/paypal').get(passport.authenticate('paypal')); + app.route('/api/auth/paypal/callback').get(users.oauthCallback('paypal')); }; diff --git a/package.json b/package.json index aabab5ab..9af09003 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "passport-linkedin": "~0.1.3", "passport-google-oauth": "~0.1.5", "passport-github": "~0.1.5", + "passport-paypal-openidconnect": "^0.1.1", "acl": "~0.4.4", "socket.io": "~1.1.0", "lodash": "~2.4.1",