Browse files

trying to get package.json to work

  • Loading branch information...
1 parent 27ca4fd commit 6cf22c26252d3444a3dd2bb86e16c6e8dc4b2562 Jonas Huckestein committed Jan 25, 2011
Showing with 1 addition and 78 deletions.
  1. +0 −75 facebook-session-cookie.coffee
  2. +0 −2 index.js
  3. +1 −1 package.json
View
75 facebook-session-cookie.coffee
@@ -1,75 +0,0 @@
-crypto = require 'crypto'
-
-class FBSession
-
- constructor: (@app_id, @app_secret, @domain) ->
- @state = 'logged_out'
-
- initialize: (req) =>
- @req = req
- @_eatCookie req
- req.fb_session = if @isLoggedIn() then this else null
-
- getId: => @params?.uid
- getAccessToken: => @params?.access_token
- getParams: => @params
-
- # TODO this doesn't log the user out of facebook so
- # for now let's keep the logout shit on the client side
- # logout: () =>
- # res.setCookie 'fbs_'+@app_id, '',
- # domain: @domain,
- # expires: new Date( new Date().getTime() - 30 * 24 * 60 * 60 * 1000 )
-
- isLoggedIn: -> @state is 'logged_in'
-
- _getSignature: (params) =>
- hash = crypto.createHash 'md5'
- keys = Object.keys(params).sort()
- payload = ""
- payload += "#{key}=#{value}" for key, value of params
- payload += @app_secret
- hash.update payload
- return hash.digest 'hex'
-
- _verifyFBSession: (session) =>
- verify_signature = session.sig
- delete session.sig
- return verify_signature is @_getSignature(session)
-
- # taken from connect's cookieDecoder middleware.
- _getCookies: (req) =>
- cookies = {}
- header = req.headers.cookie
- return cookies unless header
- pairs = header.split /[;,] */
- for pair in pairs
- eqlIndex = pair.indexOf '='
- key = pair.substr(0, eqlIndex).trim().toLowerCase()
- val = pair.substr(++eqlIndex, pair.length).trim()
- if val[0] is '"'
- val = val.slice(1, -1)
- if cookies[key] is undefined
- cookies[key] = require('querystring').unescape(val, true)
- return cookies
-
- _eatCookie: (req) =>
- cookies = req.cookies or @_getCookies req
- cookie = cookies["fbs_#{@app_id}"]
- return false unless cookie
- params = require('querystring').parse cookie
- if @_verifyFBSession(params)
- @state = 'logged_in'
- @params = params
- return true
- else return false
-
-# Hook up this middleware and you're set
-module.exports = (fb_app_id, fb_app_secret, domain) ->
- return ((req, res, next) ->
- fb_session = new FBSession(fb_app_id, fb_app_secret, domain)
- fb_session.initialize req
- next()
- )
-
-module.exports.FBSession = FBSession
View
2 index.js
@@ -1,2 +0,0 @@
-require('coffee-script');
-module.exports = require('./facebook-session-cookie.coffee');
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "facebook-session-cookie",
- "version": "0.1.0",
+ "version": "0.1.1",
"description": "nodejs/connect middleware that eats facebook cookies that eats and validates facebook cookies from client FB.login() calls and makes the session available as req.fb_session",
"author": {
"name": "Jonas Huckestein",

0 comments on commit 6cf22c2

Please sign in to comment.