Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #610 from trainerbill/PayPalAuth4
Browse files Browse the repository at this point in the history
PayPal Authentication
  • Loading branch information
lirantal committed Jul 15, 2015
2 parents a146a30 + fe1d584 commit 855a399
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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',
Expand Down
6 changes: 6 additions & 0 deletions config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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: {
Expand Down
6 changes: 6 additions & 0 deletions config/env/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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: {
Expand Down
Binary file added modules/users/client/img/buttons/paypal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ <h3 class="col-md-12 text-center">Sign in using your social accounts</h3>
<a href="/api/auth/github" target="_self" class="undecorated-link">
<img src="/modules/users/img/buttons/github.png">
</a>
<a href="/api/auth/paypal" target="_self" class="undecorated-link">
<img src="/modules/users/img/buttons/paypal.png">
</a>
</div>
<div ui-view></div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ <h3 class="col-md-12 text-center" data-ng-show="hasConnectedAdditionalSocialAcco
<i class="glyphicon glyphicon-plus"></i>
</a>
</div>
<div class="social-account-container" data-ng-hide="isConnectedSocialAccount('paypal')">
<img ng-src="/modules/users/img/buttons/paypal.png">
<a class="btn btn-success btn-remove-account" href="/api/auth/paypal" target="_self">
<i class="glyphicon glyphicon-plus"></i>
</a>
</div>
</div>
</section>
42 changes: 42 additions & 0 deletions modules/users/server/config/strategies/paypal.js
Original file line number Diff line number Diff line change
@@ -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);
}
));
};
4 changes: 4 additions & 0 deletions modules/users/server/routes/auth.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"passport": "~0.2.2",
"passport-facebook": "^2.0.0",
"passport-github": "~0.1.5",
"passport-paypal-openidconnect": "^0.1.1",
"passport-google-oauth": "~0.2.0",
"passport-linkedin": "~0.1.3",
"passport-local": "^1.0.0",
Expand Down

0 comments on commit 855a399

Please sign in to comment.