omab / django-social-auth

Django social authentication made simple
https://groups.google.com/group/django-social-auth
BSD 3-Clause "New" or "Revised" License
2.65k stars 756 forks source link

401 Client Error: Unauthorized for url: https://oauth.vk.com/access_token #853

Closed GitBib closed 7 years ago

GitBib commented 7 years ago

When you register a new account there is such a thing. HTTPError at /social/complete/vk-oauth2/ 401 Client Error: Unauthorized for url: https://oauth.vk.com/access_token Request Method: GET Request URL: http://site.com/social/complete/vk-oauth2/?redirect_state=*******&code=*******&state=*****

Django Version:1.10.5 Python Version: 3.5.2 python-social-auth==0.3.6 social-auth-app-django==1.1.0 social-auth-core==1.2.0

settings.py

INSTALLED_APPS = [
    ****
    'social.apps.django_app.default',
    'social_django',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [ 
                *****
                'social.apps.django_app.context_processors.backends',
                'social.apps.django_app.context_processors.login_redirect',
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'social.backends.vk.VKOAuth2'
)

LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_VK_OAUTH2_KEY = '********'
SOCIAL_AUTH_VK_OAUTH2_SECRET = '*********'
SOCIAL_AUTH_VK_OAUTH2_SCOPE = ['friends', 'offline', 'groups', 'email']

urls.py
urlpatterns = [
   *****
    url('^social/', include('social.apps.django_app.urls', namespace='social')),
    url('^auth/', include('django.contrib.auth.urls', namespace='auth')),
]
/app/.heroku/python/lib/python3.5/site-packages/social_django/utils.py in wrapper
            return func(request, backend, *args, **kwargs) ...
▼ Local vars
Variable    Value
args    
()
backend 
'vk-oauth2'
func    
<function complete at 0x7fe7705728c8>
kwargs  
{}
load_strategy   
<function load_strategy at 0x7fe7704c8f28>
redirect_uri    
'social:complete'
request 
<WSGIRequest: GET '/social/complete/vk-oauth2/?redirect_state=*******&code=*********&state=*******'>
uri 
'/social/complete/vk-oauth2/'
/app/.heroku/python/lib/python3.5/site-packages/social_django/views.py in complete
                       redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs) ...
▼ Local vars
Variable    Value
args    
()
backend 
'vk-oauth2'
kwargs  
{}
request 
<WSGIRequest: GET '/social/complete/vk-oauth2/?redirect_state=*******&code=*********&state=*******'>
/app/.heroku/python/lib/python3.5/site-packages/social_core/actions.py in do_complete
        user = backend.complete(user=user, *args, **kwargs) ...
▼ Local vars
Variable    Value
args    
()
backend 
<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>
data    
{'code': '*********',
 'redirect_state': '*******',
 'state': '*******'}
is_authenticated    
False
kwargs  
{}
login   
<function _do_login at 0x7fe770572e18>
partial 
None
redirect_name   
'next'
user    
None
/app/.heroku/python/lib/python3.5/site-packages/social_core/backends/base.py in complete
        return self.auth_complete(*args, **kwargs) ...
▼ Local vars
Variable    Value
args    
()
kwargs  
{'user': None}
self    
<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>
/app/.heroku/python/lib/python3.5/site-packages/social_core/utils.py in wrapper
            return func(*args, **kwargs) ...
▼ Local vars
Variable    Value
args    
(<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>,)
func    
<function BaseOAuth2.auth_complete at 0x7fe76e650840>
kwargs  
{'user': None}
/app/.heroku/python/lib/python3.5/site-packages/social_core/backends/oauth.py in auth_complete
            method=self.ACCESS_TOKEN_METHOD ...
▼ Local vars
Variable    Value
args    
()
kwargs  
{'user': None}
self    
<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>
state   
'*******'
/app/.heroku/python/lib/python3.5/site-packages/social_core/backends/oauth.py in request_access_token
        return self.get_json(*args, **kwargs) ...
▼ Local vars
Variable    Value
args    
('https://oauth.vk.com/access_token',)
kwargs  
{'auth': None,
 'data': {'client_id': '*****',
          'client_secret': '*********',
          'code': '*********',
          'grant_type': 'authorization_code',
          'redirect_uri': 'http://site.com/social/complete/vk-oauth2/?redirect_state=*******'},
 'headers': {'Accept': 'application/json',
             'Content-Type': 'application/x-www-form-urlencoded'},
 'method': 'POST'}
self    
<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>
/app/.heroku/python/lib/python3.5/site-packages/social_core/backends/base.py in get_json
        return self.request(url, *args, **kwargs).json() ...
▼ Local vars
Variable    Value
args    
()
kwargs  
{'auth': None,
 'data': {'client_id': '*****',
          'client_secret': '*********',
          'code': '*********',
          'grant_type': 'authorization_code',
          'redirect_uri': 'http://site.com/social/complete/vk-oauth2/?redirect_state=*******'},
 'headers': {'Accept': 'application/json',
             'Content-Type': 'application/x-www-form-urlencoded'},
 'method': 'POST'}
self    
<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>
url 
'https://oauth.vk.com/access_token'
/app/.heroku/python/lib/python3.5/site-packages/social_core/backends/base.py in request
        response.raise_for_status() ...
▼ Local vars
Variable    Value
args    
()
kwargs  
{'auth': None,
 'data': {'client_id': '******',
          'client_secret': '******',
          'code': '*********',
          'grant_type': 'authorization_code',
          'redirect_uri': 'http://site.com/social/complete/vk-oauth2/?redirect_state=*******'},
 'headers': {'Accept': 'application/json',
             'Content-Type': 'application/x-www-form-urlencoded'},
 'timeout': None}
method  
'POST'
response    
<Response [401]>
self    
<social_core.backends.vk.VKOAuth2 object at 0x7fe76e5526a0>
url 
'https://oauth.vk.com/access_token'
/app/.heroku/python/lib/python3.5/site-packages/requests/models.py in raise_for_status
            raise HTTPError(http_error_msg, response=self) ...
▼ Local vars
Variable    Value
http_error_msg  
'401 Client Error: Unauthorized for url: https://oauth.vk.com/access_token'
reason  
'Unauthorized'
self    
<Response [401]>
ThunderTrent commented 7 years ago

I'm having same error for Facebook authentications.. trying to figure out what's going on.

ediskandarov commented 7 years ago

@GitBib take another key from application settings

screen shot 2017-04-23 at 23 04 13
tyapkov commented 7 years ago

I have the same error. Cannot figure out what to do.

omab commented 7 years ago

This project was marked as deprecated on Aug 29, 2013