PayPal Authentication

This commit is contained in:
Andrew Throener
2015-07-02 07:44:58 -05:00
parent 426ce9e8cc
commit 8694b7e976
9 changed files with 74 additions and 0 deletions

View File

@@ -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',

View File

@@ -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: {

6
config/env/test.js vendored
View File

@@ -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: {

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@@ -16,6 +16,9 @@
<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>

View File

@@ -40,5 +40,11 @@
<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>

View File

@@ -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);
}
));
};

View File

@@ -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'));
};

View File

@@ -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",