Skip to content

Commit

Permalink
Merge pull request mashery#12 from synedra/master
Browse files Browse the repository at this point in the history
Cookie behavior improvements for OAuth-based sessions
  • Loading branch information
mansilladev committed Jan 6, 2012
2 parents f2796a6 + be8b9e6 commit d3bebe8
Show file tree
Hide file tree
Showing 3 changed files with 4,168 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app.js
Expand Up @@ -329,11 +329,15 @@ function processRequest(req, res, next) {
],
function(err, results) {

var apiKey = reqQuery.apiKey || results[0],
apiSecret = reqQuery.apiSecret || results[1],
var apiKey = (typeof reqQuery.apiKey == "undefined" || reqQuery.apiKey == "undefined")?results[0]:reqQuery.apiKey,
apiSecret = (typeof reqQuery.apiSecret == "undefined" || reqQuery.apiSecret == "undefined")?results[1]:reqQuery.apiSecret,
accessToken = results[2],
accessTokenSecret = results[3];

console.log(apiKey);
console.log(apiSecret);
console.log(accessToken);
console.log(accessTokenSecret);

var oa = new OAuth(apiConfig.oauth.requestURL || null,
apiConfig.oauth.accessURL || null,
apiKey || null,
Expand Down Expand Up @@ -567,6 +571,21 @@ function processRequest(req, res, next) {
// Passes variables to the view
app.dynamicHelpers({
session: function(req, res) {
// If api wasn't passed in as a parameter, check the path to see if it's there
if (!req.params.api) {
pathName = req.url.replace('/','');
// Is it a valid API - if there's a config file we can assume so
fs.stat('public/data/' + pathName + '.json', function (error, stats) {
if (stats) {
req.params.api = pathName;
}
});
}
// If the cookie says we're authed for this particular API, set the session to authed as well
if (req.params.api && req.session[req.params.api] && req.session[req.params.api]['authed']) {
req.session['authed'] = true;
}

return req.session;
},
apiInfo: function(req, res) {
Expand Down
17 changes: 17 additions & 0 deletions public/data/apiconfig.json
@@ -1,4 +1,21 @@
{
"linkedin": {
"name": "LinkedIn",
"protocol": "http",
"baseURL": "api.linkedin.com",
"publicPath": "",
"privatePath": "/v1",
"auth": "oauth",
"oauth": {
"type": "three-legged",
"requestURL": "https://api.linkedin.com/uas/oauth/requestToken",
"signinURL": "https://api.linkedin.com/uas/oauth/authorize?oauth_token=",
"accessURL": "https://api.linkedin.com/uas/oauth/accessToken",
"version": "1.0",
"crypt": "HMAC-SHA1"
},
"keyParam":""
},
"klout": {
"name": "Klout API",
"protocol": "http",
Expand Down

0 comments on commit d3bebe8

Please sign in to comment.