Permalink
Browse files

Expose raw and parsed JSON response on profile.

  • Loading branch information...
1 parent 0e3a04e commit 3093f5c88ea5c07952b0325be07d8a7a10878296 @jaredhanson committed Mar 5, 2012
Showing with 19 additions and 10 deletions.
  1. +13 −10 lib/passport-facebook/strategy.js
  2. +6 −0 test/strategy-test.js
@@ -80,18 +80,21 @@ Strategy.prototype.userProfile = function(accessToken, done) {
if (err) { return done(err); }
try {
- o = JSON.parse(body);
+ var json = JSON.parse(body);
var profile = { provider: 'facebook' };
- profile.id = o.id;
- profile.username = o.username;
- profile.displayName = o.name;
- profile.name = { familyName: o.last_name,
- givenName: o.first_name,
- middleName: o.middle_name };
- profile.gender = o.gender;
- profile.profileUrl = o.link;
- profile.emails = [{ value: o.email }];
+ profile.id = json.id;
+ profile.username = json.username;
+ profile.displayName = json.name;
+ profile.name = { familyName: json.last_name,
+ givenName: json.first_name,
+ middleName: json.middle_name };
+ profile.gender = json.gender;
+ profile.profileUrl = json.link;
+ profile.emails = [{ value: json.email }];
+
+ profile._raw = body;
+ profile._json = json;
done(null, profile);
} catch(e) {
@@ -65,6 +65,12 @@ vows.describe('FacebookStrategy').addBatch({
assert.lengthOf(profile.emails, 1);
assert.equal(profile.emails[0].value, 'jaredhanson@example.com');
},
+ 'should set raw property' : function(err, profile) {
+ assert.isString(profile._raw);
+ },
+ 'should set json property' : function(err, profile) {
+ assert.isObject(profile._json);
+ },
},
},

0 comments on commit 3093f5c

Please sign in to comment.