From f20cfdd982436eaeb9c9d1e5f3c02a62706263ba Mon Sep 17 00:00:00 2001 From: Stas Kravets Date: Tue, 12 Jul 2011 00:14:05 +0400 Subject: [PATCH] VKontakte error checking. --- social_auth/backends/contrib/vkontakte.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/social_auth/backends/contrib/vkontakte.py b/social_auth/backends/contrib/vkontakte.py index 1efb69f..5d9191c 100644 --- a/social_auth/backends/contrib/vkontakte.py +++ b/social_auth/backends/contrib/vkontakte.py @@ -10,7 +10,7 @@ from django.contrib.auth import authenticate from django.utils import simplejson from urllib import urlencode, unquote -from urllib2 import Request, urlopen +from urllib2 import Request, urlopen, HTTPError from hashlib import md5 from time import time @@ -127,7 +127,12 @@ class VKontakteOAuth2(BaseOAuth2): if stop: return None - return super(VKontakteOAuth2, self).auth_complete(*args, **kwargs) + try: + auth_result = super(VKontakteOAuth2, self).auth_complete(*args, **kwargs) + except HTTPError: # VKontakte returns HTTPError 400 if cancelled + raise ValueError('Authentication cancelled') + + return auth_result def user_data(self, access_token): """Return user data from VKontakte OpenAPI""" -- 2.39.5