Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Provider VKontakte implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolf authored and eriktaubeneck committed Jul 10, 2014
1 parent 5eded02 commit c2582a5
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions flask_social/providers/vk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
"""
flask.ext.social.providers.vk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This module contains the Flask-Social vkontakte code
:copyright: (c) 2014 by Sergey Nuzhdin.
:license: MIT, see LICENSE for more details.
"""

from __future__ import absolute_import

import vkontakte

config = {
'id': 'vk',
'name': 'VK',
'install': 'pip install vkontakte',
'module': 'flask_social.providers.vk',
'base_url': 'https://api.vk.com/method/',
'request_token_url': None,
'access_token_url': 'https://oauth.vk.com/access_token',
'authorize_url': 'https://oauth.vk.com/authorize',
'request_token_params': {}
}


def get_api(connection, **kwargs):
return vkontakte.API(
api_id=kwargs.get('consumer_key'),
api_secret=kwargs.get('consumer_secret')
)


def get_provider_user_id(response, **kwargs):
return str(response['user_id']) if response else None


def get_connection_values(response, **kwargs):
if not response:
return None

access_token = response['access_token']
vk = vkontakte.API(token=response['access_token'])
profile = vk.getProfiles(
uids=response['user_id'],
fields='first_name,last_name,photo_100,screen_name')[0]

profile_url = "http://vk.com/id%s" % response['user_id']
fullname = u'%s %s' % (profile['first_name'], profile['last_name'])
return dict(
provider_id=config['id'],
provider_user_id=str(profile['uid']),
access_token=access_token,
secret=None,
display_name=profile.get('screen_name', fullname),
full_name=fullname,
profile_url=profile_url,
image_url=profile.get('photo_100')
)

0 comments on commit c2582a5

Please sign in to comment.