Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fetch `username` and `photos` fields

  • Loading branch information...
commit 220b961ac8b8baa3236097da960a891c208520b9 1 parent 45dea72
Stepan Stolyarov authored
Showing with 17 additions and 5 deletions.
  1. +17 −5 lib/passport-vkontakte/strategy.js
22 lib/passport-vkontakte/strategy.js
View
@@ -146,20 +146,27 @@ Strategy.prototype.authenticate = function(req, options) {
* This function constructs a normalized profile, with the following properties:
*
* - `provider` always set to `vkontakte`
- * - `id` the user's Facebook ID
- * - `username` the user's Facebook username
+ * - `id` the user's VK.com ID
* - `displayName` the user's full name
* - `name.familyName` the user's last name
* - `name.givenName` the user's first name
* - `gender` the user's gender: `male` or `female`
- * - `profileUrl` the URL of the profile for the user on Facebook
+ * - `photos` array of `{ value: 'url' }`
*
* @param {String} accessToken
* @param {Function} done
* @api protected
*/
Strategy.prototype.userProfile = function(accessToken, uid, done) {
- this._oauth2.getProtectedResource('https://api.vk.com/method/getProfiles?uids=' + uid, accessToken, function (err, body, res) {
+ var fields = [
+ 'uid'
+ , 'first_name'
+ , 'last_name'
+ , 'screen_name'
+ , 'sex'
+ , 'photo'
+ ].join(',');
+ this._oauth2.getProtectedResource('https://api.vk.com/method/getProfiles?fields=' + fields + '&uids=' + uid, accessToken, function (err, body, res) {
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
try {
@@ -169,7 +176,7 @@ Strategy.prototype.userProfile = function(accessToken, uid, done) {
var profile = { provider: 'vkontakte' };
profile.id = json.uid;
- profile.username = json.username;
+ profile.username = json.screen_name;
profile.displayName = json.first_name + ' ' + json.last_name;
profile.name = { familyName: json.last_name,
givenName: json.first_name };
@@ -177,6 +184,11 @@ Strategy.prototype.userProfile = function(accessToken, uid, done) {
if (json.sex) {
profile.gender = json.sex == 1 ? 'female' : 'male';
}
+
+ profile.photos = [{
+ value: json.photo,
+ type: 'thumbnail'
+ }];
profile._raw = body;
profile._json = json;
Please sign in to comment.
Something went wrong with that request. Please try again.