]> git.parisson.com Git - django-social-auth.git/commitdiff
Merge remote branch 'upstream/master'
authorStas Kravets <skravets@internal-rfc1918.hn.nnov.stream.ru>
Wed, 19 Jan 2011 10:23:07 +0000 (13:23 +0300)
committerStas Kravets <skravets@internal-rfc1918.hn.nnov.stream.ru>
Wed, 19 Jan 2011 10:23:07 +0000 (13:23 +0300)
1  2 
example/app/views.py
example/local_settings.py.template
example/settings.py
example/templates/home.html
example/templates/vkontakte.html
setup.py
social_auth/backends/contrib/vkontakte.py

index 941c915b0fcdbaf08968b318ba27bf37050d9386,50f3b3ea9fb71641a4d0b1cffde95a5b7181b182..16cdb962b27c286f16396869f918893583e0b583
@@@ -4,9 -4,7 +4,6 @@@ from django.contrib.auth.decorators imp
  from django.template import RequestContext
  from django.shortcuts import render_to_response
  
- from social_auth.vk import add_VK_Auth
- add_VK_Auth()
--
  def home(request):
      """Home view, displays login mechanism"""
      if request.user.is_authenticated():
index 300a597fc8b3347d7850376a497c378d376be324,e43eba892d9a604a4488d5221778c3fd0f6eec60..0729e75ae0dbd44796edab517f9e1051dbff98fa
@@@ -7,9 -7,6 +7,8 @@@ ORKUT_CONSUMER_SECRET             = '
  SOCIAL_AUTH_CREATE_USERS          = True
  SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False
  SOCIAL_AUTH_DEFAULT_USERNAME      = 'socialauth_user'
--SOCIAL_AUTH_COMPLETE_URL_NAME     = 'social:complete'
++SOCIAL_AUTH_COMPLETE_URL_NAME     = 'complete'
  LOGIN_ERROR_URL                   = '/login/error/'
- VKONTAKTE_LOCAL_HTML              = ''
 +VKONTAKTE_APP_ID                  = ''
 +VKONTAKTE_APP_SECRET              = ''
  #SOCIAL_AUTH_USER_MODEL            = 'app.CustomUser'
index 59fe4229d7f14f2817bff59d57c9cbe404c63d12,f2e7d7c8d733d2220adffb8083a700b1856507a4..ac731eac194b068e919f357942f9d70dd9d7d4ed
@@@ -62,14 -62,13 +62,14 @@@ INSTALLED_APPS = 
  )
  
  AUTHENTICATION_BACKENDS = (
-     'social_auth.backends.TwitterBackend',
-     'social_auth.backends.FacebookBackend',
-     'social_auth.backends.GoogleOAuthBackend',
-     'social_auth.backends.GoogleBackend',
-     'social_auth.backends.YahooBackend',
+     'social_auth.backends.twitter.TwitterBackend',
+     'social_auth.backends.facebook.FacebookBackend',
+     'social_auth.backends.google.GoogleOAuthBackend',
+     'social_auth.backends.google.GoogleBackend',
+     'social_auth.backends.yahoo.YahooBackend',
      'social_auth.backends.OpenIDBackend',
-     'social_auth.backends.LiveJournalBackend',
-     'social_auth.vk.VKontakteBackend',
+     'social_auth.backends.contrib.livejournal.LiveJournalBackend',
++    'social_auth.backends.contrib.vkontakte.VKontakteBackend',
      'django.contrib.auth.backends.ModelBackend',
  )
  
Simple merge
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..137a105e842d127b9ff761a1593d89dac147a978
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,38 @@@
++{% extends "base.html" %}
++
++{% block heading %}<a href="http://www.vkontakte.ru">VKontakte</a> login{% endblock %}
++
++{% block content %}
++
++<script src="http://vkontakte.ru/js/api/openapi.js" type="text/javascript"></script>
++
++<script type="text/javascript">
++      var vkAppId = {{ VK_APP_ID|default:"null" }};
++
++      if (vkAppId)
++              VK.init({ apiId: vkAppId });
++
++      function authVK() {
++              if (!vkAppId) {
++                      alert ("Please specify VKontakte APP ID in your local settings file");
++                      return false;
++              }
++              
++              VK.Auth.login(function(response) {
++                      var params = "";
++                      if (response.session) {
++                              params = "first_name=" + encodeURI(response.session.user.first_name) + "&last_name=" + encodeURI(response.session.user.last_name);
++                              params += "&nickname=" + encodeURI(response.session.user.nickname) + "&id=" + encodeURI(response.session.user.id);
++                      }
++                      window.location = "{{ VK_COMPLETE_URL }}?" + params;
++
++              });
++              return false;
++      }
++      
++      window.onload = authVK();
++      
++</script>
++
++<div id="status">Logging in, please wait...</div>
++{% endblock %}
diff --cc setup.py
index 321d75951b1c5e8265178785e575380c7c36e10a,b1c22812b4eede914fe2ab8dc2b040f8e7f79bde..478f0334314244fbaeeaf07ab244ae1e0f9234f7
+++ b/setup.py
@@@ -32,9 -32,12 +32,11 @@@ setup(name='django-social-auth'
        license='GPL',
        keywords='django, openid, oath, social auth, application',
        url='https://github.com/omab/django-social-auth',
-       packages=['social_auth'],
+       packages=['social_auth',
+                 'social_auth.backends',
+                 'social_auth.backends.contrib'],
        long_description=long_description(),
 -      install_requires=['django>=1.2',
 -                        'oauth>=1.0',
 +      install_requires=['oauth>=1.0',
                          'python_openid>=2.2'],
        classifiers=['Framework :: Django',
                     'Development Status :: 4 - Beta',
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..673ec41be9fc6c886180c7edc45d84b73f81d9da
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,81 @@@
++"""
++VKontakte OpenAPI support.
++
++This contribution adds support for VKontakte OpenAPI service in the form
++www.vkontakte.ru. Username is retrieved from the identity returned by server.
++"""
++
++from django.conf import settings
++from django.contrib.auth import authenticate
++from urllib import unquote
++import md5
++
++from social_auth.backends import SocialAuthBackend, BaseAuth, USERNAME
++
++VKONTAKTE_LOCAL_HTML  = 'vkontakte.html'
++
++class VKontakteBackend(SocialAuthBackend):
++    """VKontakte authentication backend"""
++    name = 'vkontakte'
++
++    def get_user_id(self, details, response):
++        """Return user unique id provided by VKontakte"""
++        return int(response.GET['id'])
++    
++    def get_user_details(self, response):
++        """Return user details from VKontakte request"""
++        nickname = unquote(response.GET['nickname'])
++        values = { USERNAME: response.GET['id'] if len(nickname) == 0 else nickname, 'email': '', 'fullname': '',
++                  'first_name': unquote(response.GET['first_name']), 'last_name': unquote(response.GET['last_name'])}
++        return values
++
++
++class VKontakteAuth(BaseAuth):
++    """VKontakte OpenAPI authorization mechanism"""
++    AUTH_BACKEND = VKontakteBackend
++    APP_ID = settings.VKONTAKTE_APP_ID
++    
++    def auth_html(self):
++        """Returns local VK authentication page, not necessary for VK to authenticate """
++        from django.core.urlresolvers import reverse
++        from django.template import RequestContext, loader
++        
++        dict = { 'VK_APP_ID'      : self.APP_ID,
++                 'VK_COMPLETE_URL': reverse(settings.SOCIAL_AUTH_COMPLETE_URL_NAME, args=[VKontakteBackend.name]) }
++        
++        vk_template = loader.get_template(VKONTAKTE_LOCAL_HTML)
++        context = RequestContext(self.request, dict)
++    
++        return vk_template.render(context)
++        
++    def auth_complete(self, *args, **kwargs):
++        """Performs check of authentication in VKontakte, returns User if succeeded"""
++        app_cookie = 'vk_app_' + self.APP_ID
++        
++        if not 'id' in self.request.GET or not app_cookie in self.request.COOKIES:
++            raise ValueError('VKontakte authentication is not completed')
++        
++        cookie_dict = dict(item.split('=') for item in self.request.COOKIES[app_cookie].split('&'))
++        check_str = ''.join([item + '=' + cookie_dict[item] for item in ['expire', 'mid', 'secret', 'sid']])
++        
++        hash = md5.new(check_str + settings.VKONTAKTE_APP_SECRET).hexdigest()
++        
++        if hash != cookie_dict['sig']:
++            raise ValueError('VKontakte authentication failed: invalid hash')       
++        else:
++            kwargs.update({'response': self.request, self.AUTH_BACKEND.name: True})
++            return authenticate(*args, **kwargs)
++
++    @property
++    def uses_redirect(self):
++        """VKontakte does not require visiting server url in order
++        to do authentication, so auth_xxx methods are not needed to be called.
++        Their current implementation is just an example"""
++        return False
++    
++    
++# Backend definition
++BACKENDS = {
++    'vkontakte': VKontakteAuth,
++}
++