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

Commit 8694b7e

Browse files
committed
PayPal Authentication
1 parent 426ce9e commit 8694b7e

File tree

9 files changed

+74
-0
lines changed

9 files changed

+74
-0
lines changed

config/env/development.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module.exports = {
2929
clientID: process.env.GITHUB_ID || 'APP_ID',
3030
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
3131
callbackURL: '/api/auth/github/callback'
32+
},
33+
paypal: {
34+
clientID: process.env.PAYPAL_ID || 'CLIENT_ID',
35+
clientSecret: process.env.PAYPAL_SECRET || 'CLIENT_SECRET',
36+
callbackURL: '/api/auth/paypal/callback',
37+
sandbox: true
3238
},
3339
mailer: {
3440
from: process.env.MAILER_FROM || 'MAILER_FROM',

config/env/production.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ module.exports = {
2727
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
2828
callbackURL: '/api/auth/github/callback'
2929
},
30+
paypal: {
31+
clientID: process.env.PAYPAL_ID || 'CLIENT_ID',
32+
clientSecret: process.env.PAYPAL_SECRET || 'CLIENT_SECRET',
33+
callbackURL: '/api/auth/paypal/callback',
34+
sandbox: false
35+
},
3036
mailer: {
3137
from: process.env.MAILER_FROM || 'MAILER_FROM',
3238
options: {

config/env/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ module.exports = {
3131
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
3232
callbackURL: '/api/auth/github/callback'
3333
},
34+
paypal: {
35+
clientID: process.env.PAYPAL_ID || 'CLIENT_ID',
36+
clientSecret: process.env.PAYPAL_SECRET || 'CLIENT_SECRET',
37+
callbackURL: '/api/auth/paypal/callback',
38+
sandbox: true
39+
},
3440
mailer: {
3541
from: process.env.MAILER_FROM || 'MAILER_FROM',
3642
options: {
5.11 KB
Loading

modules/users/client/views/authentication/authentication.client.view.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ <h3 class="col-md-12 text-center">Sign in using your social accounts</h3>
1616
<a href="/api/auth/github" target="_self" class="undecorated-link">
1717
<img src="/modules/users/img/buttons/github.png">
1818
</a>
19+
<a href="/api/auth/paypal" target="_self" class="undecorated-link">
20+
<img src="/modules/users/img/buttons/paypal.png">
21+
</a>
1922
</div>
2023
<div ui-view></div>
2124
</section>

modules/users/client/views/settings/manage-social-accounts.client.view.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,11 @@ <h3 class="col-md-12 text-center" data-ng-show="hasConnectedAdditionalSocialAcco
4040
<i class="glyphicon glyphicon-plus"></i>
4141
</a>
4242
</div>
43+
<div class="social-account-container" data-ng-hide="isConnectedSocialAccount('paypal')">
44+
<img ng-src="/modules/users/img/buttons/paypal.png">
45+
<a class="btn btn-success btn-remove-account" href="/api/auth/paypal" target="_self">
46+
<i class="glyphicon glyphicon-plus"></i>
47+
</a>
48+
</div>
4349
</div>
4450
</section>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
var passport = require('passport'),
7+
PayPalStrategy = require('passport-paypal-openidconnect').Strategy,
8+
users = require('../../controllers/users.server.controller');
9+
10+
module.exports = function (config) {
11+
passport.use(new PayPalStrategy({
12+
clientID: config.paypal.clientID,
13+
clientSecret: config.paypal.clientSecret,
14+
callbackURL: config.paypal.callbackURL,
15+
scope: 'openid profile email',
16+
sandbox: config.paypal.sandbox,
17+
passReqToCallback: true
18+
19+
},
20+
function(req, accessToken, refreshToken, profile, done) {
21+
// Set the provider data and include tokens
22+
var providerData = profile._json;
23+
providerData.accessToken = accessToken;
24+
providerData.refreshToken = refreshToken;
25+
26+
// Create the user OAuth profile
27+
var providerUserProfile = {
28+
firstName: profile.name.givenName,
29+
lastName: profile.name.familyName,
30+
displayName: profile.displayName,
31+
email: profile._json.email,
32+
username: profile.username,
33+
provider: 'paypal',
34+
providerIdentifierField: 'user_id',
35+
providerData: providerData
36+
};
37+
38+
// Save the user OAuth profile
39+
users.saveOAuthUserProfile(req, providerUserProfile, done);
40+
}
41+
));
42+
};

modules/users/server/routes/auth.server.routes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ module.exports = function(app) {
5050
// Setting the github oauth routes
5151
app.route('/api/auth/github').get(passport.authenticate('github'));
5252
app.route('/api/auth/github/callback').get(users.oauthCallback('github'));
53+
54+
// Setting the paypal oauth routes
55+
app.route('/api/auth/paypal').get(passport.authenticate('paypal'));
56+
app.route('/api/auth/paypal/callback').get(users.oauthCallback('paypal'));
5357
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"passport-linkedin": "~0.1.3",
4141
"passport-google-oauth": "~0.1.5",
4242
"passport-github": "~0.1.5",
43+
"passport-paypal-openidconnect": "^0.1.1",
4344
"acl": "~0.4.4",
4445
"socket.io": "~1.1.0",
4546
"lodash": "~2.4.1",

0 commit comments

Comments
 (0)