passport isAuthorized middleware. Fixed headers already sent errors.
This commit is contained in:
4
app.js
4
app.js
@ -61,8 +61,8 @@ app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSett
|
|||||||
app.get('/partials/:name', home.partials);
|
app.get('/partials/:name', home.partials);
|
||||||
|
|
||||||
app.get('/api', api.getApi);
|
app.get('/api', api.getApi);
|
||||||
app.get('/api/foursquare', passportConf.isAuthenticated, api.getFoursquare);
|
app.get('/api/foursquare', passportConf.isAuthenticated, passportConf.isAuthorized, api.getFoursquare);
|
||||||
app.get('/api/tumblr', passportConf.isAuthenticated, api.getTumblr);
|
app.get('/api/tumblr', passportConf.isAuthenticated, passportConf.isAuthorized, api.getTumblr);
|
||||||
app.get('/api/facebook', passportConf.isAuthenticated, api.getFacebook);
|
app.get('/api/facebook', passportConf.isAuthenticated, api.getFacebook);
|
||||||
app.get('/api/scraping', api.getScraping);
|
app.get('/api/scraping', api.getScraping);
|
||||||
app.get('/api/github', api.getGithub);
|
app.get('/api/github', api.getGithub);
|
||||||
|
@ -138,3 +138,9 @@ exports.isAuthenticated = function(req, res, next) {
|
|||||||
if (req.isAuthenticated()) return next();
|
if (req.isAuthenticated()) return next();
|
||||||
res.redirect('/login');
|
res.redirect('/login');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.isAuthorized = function(req, res, next) {
|
||||||
|
var provider = req.path.split('/').slice(-1)[0];
|
||||||
|
if (_.findWhere(req.user.tokens, { kind: provider })) next();
|
||||||
|
else res.redirect('/auth/' + provider);
|
||||||
|
};
|
@ -25,7 +25,6 @@ exports.getApi = function(req, res) {
|
|||||||
*/
|
*/
|
||||||
exports.getFoursquare = function(req, res) {
|
exports.getFoursquare = function(req, res) {
|
||||||
var foursquareToken = _.findWhere(req.user.tokens, { kind: 'foursquare' });
|
var foursquareToken = _.findWhere(req.user.tokens, { kind: 'foursquare' });
|
||||||
if (!foursquareToken) return res.redirect('/auth/foursquare');
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
trendingVenues: function(callback) {
|
trendingVenues: function(callback) {
|
||||||
var geo = geoip.lookup('4.17.136.0');
|
var geo = geoip.lookup('4.17.136.0');
|
||||||
@ -62,7 +61,6 @@ exports.getFoursquare = function(req, res) {
|
|||||||
*/
|
*/
|
||||||
exports.getTumblr = function(req, res) {
|
exports.getTumblr = function(req, res) {
|
||||||
var tumblrToken = _.findWhere(req.user.tokens, { kind: 'tumblr' });
|
var tumblrToken = _.findWhere(req.user.tokens, { kind: 'tumblr' });
|
||||||
if (!tumblrToken) return res.redirect('/auth/tumblr');
|
|
||||||
var client = tumblr.createClient({
|
var client = tumblr.createClient({
|
||||||
consumer_key: config.tumblr.consumerKey,
|
consumer_key: config.tumblr.consumerKey,
|
||||||
consumer_secret: config.tumblr.consumerSecret,
|
consumer_secret: config.tumblr.consumerSecret,
|
||||||
@ -84,7 +82,6 @@ exports.getTumblr = function(req, res) {
|
|||||||
*/
|
*/
|
||||||
exports.getFacebook = function(req, res) {
|
exports.getFacebook = function(req, res) {
|
||||||
var facebookToken = _.findWhere(req.user.tokens, { kind: 'facebook' });
|
var facebookToken = _.findWhere(req.user.tokens, { kind: 'facebook' });
|
||||||
if (!facebookToken) return res.redirect('/auth/facebook');
|
|
||||||
graph.setAccessToken(facebookToken.token);
|
graph.setAccessToken(facebookToken.token);
|
||||||
async.parallel({
|
async.parallel({
|
||||||
getMe: function(done) {
|
getMe: function(done) {
|
||||||
@ -125,7 +122,6 @@ exports.getScraping = function(req, res) {
|
|||||||
|
|
||||||
exports.getGithub = function(req, res) {
|
exports.getGithub = function(req, res) {
|
||||||
var githubToken = _.findWhere(req.user.tokens, { kind: 'github' });
|
var githubToken = _.findWhere(req.user.tokens, { kind: 'github' });
|
||||||
if (!githubToken) return res.redirect('/auth/github');
|
|
||||||
// TODO: Fix rate limit on passport-github token
|
// TODO: Fix rate limit on passport-github token
|
||||||
var github = new Github({ token: githubToken.token });
|
var github = new Github({ token: githubToken.token });
|
||||||
var repo = github.getRepo('sahat', 'requirejs-library');
|
var repo = github.getRepo('sahat', 'requirejs-library');
|
||||||
|
Reference in New Issue
Block a user