Updated foursquare routes for authorization. Now properly retrives the Oauth token when app is authorized
This commit is contained in:
10
app.js
10
app.js
@ -6,6 +6,7 @@ var express = require('express'),
|
||||
mongoose = require('mongoose'),
|
||||
passport = require('passport');
|
||||
|
||||
// TODO: Add node-opencv!!
|
||||
|
||||
// App Configuration (API Keys, Database URI)
|
||||
var config = require('./config/config.json');
|
||||
@ -67,19 +68,16 @@ app.post('/contact', contact.postContact);
|
||||
|
||||
|
||||
|
||||
// Redirect the user to Facebook for authentication. When complete,
|
||||
// Facebook will redirect the user back to the application at
|
||||
app.get('/auth/facebook', passport.authenticate('facebook'));
|
||||
// Facebook will redirect the user to this URL after approval. Finish the
|
||||
// authentication process by attempting to obtain an access token. If
|
||||
// access was granted, the user will be logged in. Otherwise,
|
||||
// authentication has failed.
|
||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
}));
|
||||
|
||||
|
||||
app.get('/auth/foursquare', api.foursquareAuth);
|
||||
app.get('/auth/foursquare/callback', api.foursquareCallback);
|
||||
|
||||
app.get('*', home.index);
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
var config = require('../config/config.json');
|
||||
|
||||
var User = require('../models/User');
|
||||
|
||||
// API PROVIDERS SETUP
|
||||
var foursquare = require('node-foursquare')({
|
||||
secrets: {
|
||||
@ -9,26 +11,41 @@ var foursquare = require('node-foursquare')({
|
||||
}
|
||||
});
|
||||
|
||||
var foursquareAccessToken = 'MY_FOURSQUARE_ACCESS_TOKEN';
|
||||
|
||||
|
||||
exports.apiBrowser = function(req, res) {
|
||||
res.render('api');
|
||||
};
|
||||
|
||||
|
||||
exports.foursquare = function(req, res) {
|
||||
|
||||
res.render('api/foursquare', {
|
||||
title: 'Foursquare API'
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* GET /auth/foursquare
|
||||
* Display Foursquare authentication screen
|
||||
*/
|
||||
exports.foursquareAuth = function(req, res) {
|
||||
res.writeHead(303, { location: foursquare.getAuthClientRedirectUrl() });
|
||||
res.end();
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /auth/foursquare/callback
|
||||
* Called when user presses Accept on the Foursquare authentication screen
|
||||
*/
|
||||
exports.foursquareCallback = function(req, res) {
|
||||
foursquare.getAccessToken({
|
||||
code: req.query.code
|
||||
},
|
||||
function(err, accessToken) {
|
||||
if (err) {
|
||||
res.send('An error was thrown: ' + err.message);
|
||||
}
|
||||
else {
|
||||
// Save the accessToken and redirect.
|
||||
}
|
||||
});
|
||||
foursquare.getAccessToken({ code: req.query.code }, function(err, accessToken) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log(accessToken);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
"passport-google": "latest",
|
||||
"underscore": "latest",
|
||||
"forever": "latest",
|
||||
"node-foursquare": "latest"
|
||||
"node-foursquare": "latest",
|
||||
|
||||
"opencv": "latest"
|
||||
}
|
||||
}
|
@ -2,3 +2,5 @@ extends ../layout
|
||||
|
||||
block content
|
||||
h1 Foursquare API
|
||||
|
||||
a.btn.btn-large.btn-primary(href='/auth/foursquare') Get Foursquare Token
|
Reference in New Issue
Block a user