Skip to content
This repository
Browse code

Expose raw and parsed JSON response on profile.

  • Loading branch information...
commit 3093f5c88ea5c07952b0325be07d8a7a10878296 1 parent 0e3a04e
Jared Hanson authored

Showing 2 changed files with 19 additions and 10 deletions. Show diff stats Hide diff stats

  1. +13 10 lib/passport-facebook/strategy.js
  2. +6 0 test/strategy-test.js
23 lib/passport-facebook/strategy.js
@@ -80,18 +80,21 @@ Strategy.prototype.userProfile = function(accessToken, done) {
80 80 if (err) { return done(err); }
81 81
82 82 try {
83   - o = JSON.parse(body);
  83 + var json = JSON.parse(body);
84 84
85 85 var profile = { provider: 'facebook' };
86   - profile.id = o.id;
87   - profile.username = o.username;
88   - profile.displayName = o.name;
89   - profile.name = { familyName: o.last_name,
90   - givenName: o.first_name,
91   - middleName: o.middle_name };
92   - profile.gender = o.gender;
93   - profile.profileUrl = o.link;
94   - profile.emails = [{ value: o.email }];
  86 + profile.id = json.id;
  87 + profile.username = json.username;
  88 + profile.displayName = json.name;
  89 + profile.name = { familyName: json.last_name,
  90 + givenName: json.first_name,
  91 + middleName: json.middle_name };
  92 + profile.gender = json.gender;
  93 + profile.profileUrl = json.link;
  94 + profile.emails = [{ value: json.email }];
  95 +
  96 + profile._raw = body;
  97 + profile._json = json;
95 98
96 99 done(null, profile);
97 100 } catch(e) {
6 test/strategy-test.js
@@ -65,6 +65,12 @@ vows.describe('FacebookStrategy').addBatch({
65 65 assert.lengthOf(profile.emails, 1);
66 66 assert.equal(profile.emails[0].value, 'jaredhanson@example.com');
67 67 },
  68 + 'should set raw property' : function(err, profile) {
  69 + assert.isString(profile._raw);
  70 + },
  71 + 'should set json property' : function(err, profile) {
  72 + assert.isObject(profile._json);
  73 + },
68 74 },
69 75 },
70 76

0 comments on commit 3093f5c

Please sign in to comment.
Something went wrong with that request. Please try again.