django allauth社会认证检索电子邮件与现有用户的电子邮件相匹配? [英] django allauth social authentication retrieved email matches an existing user's email?

查看:614
本文介绍了django allauth社会认证检索电子邮件与现有用户的电子邮件相匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Stack交换中的第一篇文章,我是Python和Django Noob试图开发一个应用程序。该应用程序使用django注册进行用户注册,然后我开始插入社交身份验证。我选择了allauth,因为它有能力在其他事情之间执行身份验证。



我遇到了同样的问题: django allauth facebook重定向到电子邮件地址匹配现有用户的电子邮件?



如果具有相同电子邮件地址的用户已经存在于数据库中(由于使用本地注册路径注册),用户登录/注册失败)。我试过上面提供的解决方案并且有问题。寻找一些帮助,并在这里提供建议。



我在socialadapter.py中具有与以上路径相同的代码。



myproject / allauth / socialaccount / socialadapter.py



我的设置中有以下内容

  LOGIN_URL ='/'
#LOGIN_REDIRECT_URL ='/'
LOGIN_REDIRECT_URL =/ users / {id} / mytags
SOCIALACCOUNT_QUERY_EMAIL = True


ACCOUNT_AUTHENTICATION_METHOD ='username_email'
SOCIALACCOUNT_EMAIL_REQUIRED = False

#create并使用特定的适配器来处理此处报告的问题
#https:/ /github.com/pennersr/django-allauth/issues/418

ACCOUNT_ADAPTER =myproject.allauth.socialaccount.MyLoginAccountAdapter
SOCIALACCOUNT_ADAPTER ='myproject.allauth.socialaccount.MySocialAccountAdapter'

在启动runserver并访问Facebook /登录时,我看到以下问题



'pre> [17 / Jul / 2014 11:49:43]GET / myproject / accounts2 / facebook / login / HTTP / 1.1500 59
-------------- --------------------------在处理请求时发生异常('127.0.0.1',58805)追溯(最近呼叫最后):文件C:\Python27\Lib\SocketServer.py,行593,在process_request_thread
self.finish_request(request,client_address)文件C:\Python27\Lib\SocketServer.py ,第334行,在finish_request
self.RequestHandlerClass(request,client_address,self)文件C:\Python27\lib\site- packages\django\core\servers\basehttp.py ,第139行,__init__
super(WSGIRequestHandler,self).__ init __(* args,** kwargs)文件C:\Python27\Lib\SocketServer.py,第651行,__init__
self.finish()文件C:\Python27\Lib\SocketServer.py,第710行,完成
self.wfile.close()文件C:\Python27\Lib \socket.py,行279,关闭
self.flush()文件C:\Python27\Lib\socket.py,行303,在flush
self._sock.sendall(view [write_offset:write_offset + buffer_size])错误:[Errno 10053]您的主机中的软件已中断已建立的连接
------------------------ ----------------错误:django.request:内部服务器错误:/ myproject / accounts2 / facebook / login / callback / Traceback(最近呼叫最后):文件C:\\ \\ python27\lib\site-packers\base.py,第109行,在get_response
response = callback(request,* callback_args,** callback_kwargs)文件 myproject\allauth\socialaccount\providers\oauth2\views.py,第51行,视图
return self.dispatch(request,* args,** kwargs)文件myproject\allauth\\ \\socialaccount\providers\oauth2\views.py,第98行,在调度
response = access_token)文件myproject\allauth\soc ialaccount\providers\facebook\views.py,第43行,在complete_login
返回fb_complete_login(请求,应用程序,access_token)文件myproject\allauth\socialaccount\providers\facebook\views .py,第31行,fb_complete_login
.sociallogin_from_response(request,extra_data)文件myproject\allauth\socialaccount\providers\base.py,第44行,在sociallogin_from_response
adapter = get_adapter()文件myproject\allauth\socialaccount\adapter.py,第150行,get_adapter
返回import_attribute(app_settings.ADAPTER)()文件myproject\allauth\utils.py line 97,in import_attribute
ret = getattr(importlib.import_module(pkg),attr)AttributeError:'module'对象没有属性'MySocialAccountAdapter'[17 / Jul / 2014 11:49:46]GET / myproject / accounts2 / facebook / login / callback /?code = AQBShGWTHnGVvlo-fOVW7xjF9RUJo-k7P23zISHC70p aAR5uWYpnI46gpHFUCC5Rz-SviDyTV RAUkZ-DhkZaHyBT2n5UBhhSwkACgCKTTgPrFLAZFBQs05AEZ67xfk-wRlF47DSjT26bbDdUmc1ptfFxP3W4qS5Y6b5Yrj iLTI3RMScOEM0EKUQjNySyj4XSAVk6wj4HcAbCVxiVv5QaH63ayxyt5Y5jQ0AOH3zsCngPaqFNJArXseMS6wfqSc8yDwcwWZKo1nGhcNtA9Gy_bqZNiTZSjPJguhT lBwbmDAJ9SUNI8AS3yzC-AKDtD2_bo&安培;状态= 441rn77wUuLH HTTP / 1.1\" 500 147978



最初即使在删除.pyc
之后,所有其他人都编译了,所以我引用了这个线程: pycompile for python3.2



并强制编译,但我仍然看到问题



任何关于我在这里做错什么的建议是非常感激的。



感谢您的宝贵时间。



-km



编辑:



环境




  • Python 2.7.5


  • allauth:0.17



解决方

好吧,我想通了这个问题,我不得不为我的适配器缺少的完整路径类的设置项。现在我可以使用Facebook登录。



但是我有另一个问题,我试图在同一个应用程序的登录时启用Linked,并在设置中输入以下条目

  SOCIALACCOUNT_PROVIDERS = \ 
{'linkedin':{'SCOPE':['r_emailaddress',
'r_fullprofile',
'r_emailaddress',
'r_contactinfo',
'r_network'],
'PROFILE_FIELDS':
[
'id' ,
'first-name',
'last-name',
'email-address',
'picture-url',
'public-profile- url',
'skills',
'headline',
'industry',
'num-connections',
'positions',
'利息,
'语言',
'认证',
'education',
'courses',
'three-current-positions',
'three-past-position ',
'建议收到',
'荣誉奖'
]
},
'facebook':{'SCOPE':['email' 'user_about_me','user_birthday',
'user_education_history','user_work_history',
'user_hometown',
'user_location',
'user_religion_politics','user_subscriptions',
'read_stream',
'read_insights',
'read_friendlists',
'user_likes',
'user_interests',
'user_groups'
],
'AUTH_PARAMS':{},
'方法':'oauth2'
},
}

现在当我使用登录页面时,我收到以下错误

  [17 / Jul / 2014 22:26:28]GET / myproject / accounts2 / linkedin / login /?process = connect HTTP / 1.1302 0 
错误:django.request:内部服务器错误:/ myproject / accounts2 / linkedin / login / callback /
追溯(最近的最后一次调用):
文件C:\Python27\lib \site-packages\django\core\handlers\base.py,第109行,get_response
response = callback(request,* callback_args,** callback_kwargs)
文件myproject \allauth\socialaccount\providers\oauth\views.py,第35行,视图
return self.dispatch(request,* args,** kwargs)
文件myproject\\ \\allauth \\socialaccount\providers\oauth\views.py,第90行,在调度
返回complete_social_login(请求,登录)
文件myproject\allauth\socialaccount\helpers.py ,line 113,in complete_social_login
sociallogin = sociallogin)
文件C:\Python27\lib\site-packages\django\dispatch\dispatcher.py,第172行,发送
response = receiver(signal = self,sender = sender,** named)
文件myproject\allauth\socialaccount\socialadapter.py,第50行,link_to_local_user
email_address = sociallogin.account.extra_data ['email']
KeyError:'email'
[17 / Jul / 2014 22:26:50]GET / myproject / accounts2 / linkedin / login / callback / ?oauth_token = 77 - d223fb8b-168f-4260-b93c-1a6e5ff2
e1e1& oauth_verifier = 52724 HTTP / 1.1500 139897

我不知道如何解决这个问题,因为LinkedIn的SCOPE有:'电子邮件地址',我如何解决这个问题作为LinkedIn中的电子邮件领域文档也表示电子邮件地址



LinkedIn字段



任何建议都不胜感激。



我对不起,我不知道如何对这个问题给予赏金,我也没有足够的空间来解决问题。



TIA



-km


This is my first post in Stack exchange, I am Python and Django Noob trying to develop an application. The application uses django-registration for user registration and then I started plugging in 'social' authentication. I chose allauth as it has the ability to perform authentication among'st other things.

I have hit the same problem that was presented in this thread: django allauth facebook redirects to signup when retrieved email matches an existing user's email?

user login/signup failing if the user with same email address already exists in the database(due to registration with local registration path). I tried the solution provided in the above post and have issues. Looking for some help and advise here.

I have exactly the same code as above in my socialadapter.py under the following path

myproject/allauth/socialaccount/socialadapter.py

I have the following in my settings

LOGIN_URL = '/'
#LOGIN_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = "/users/{id}/mytags"
SOCIALACCOUNT_QUERY_EMAIL = True


ACCOUNT_AUTHENTICATION_METHOD='username_email'
SOCIALACCOUNT_EMAIL_REQUIRED = False

#create and use specific adapter to handle the issue reported here
# https://github.com/pennersr/django-allauth/issues/418

ACCOUNT_ADAPTER = "myproject.allauth.socialaccount.MyLoginAccountAdapter"
SOCIALACCOUNT_ADAPTER = 'myproject.allauth.socialaccount.MySocialAccountAdapter'

On starting the runserver and accessing the facebook/login , I see the following issue

[17/Jul/2014 11:49:43] "GET /myproject/accounts2/facebook/login/ HTTP/1.1" 500 59
---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 58805) Traceback (most recent call last):   File "C:\Python27\Lib\SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)   File "C:\Python27\Lib\SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)   File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)   File "C:\Python27\Lib\SocketServer.py", line 651, in __init__
    self.finish()   File "C:\Python27\Lib\SocketServer.py", line 710, in finish
    self.wfile.close()   File "C:\Python27\Lib\socket.py", line 279, in close
    self.flush()   File "C:\Python27\Lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 10053] An established connection was aborted by the software in your host machine
---------------------------------------- ERROR:django.request:Internal Server Error: /myproject/accounts2/facebook/login/callback/ Traceback (most recent call last):   File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)   File "myproject\allauth\socialaccount\providers\oauth2\views.py", line 51, in view
    return self.dispatch(request, *args, **kwargs)   File "myproject\allauth\socialaccount\providers\oauth2\views.py", line 98, in dispatch
    response=access_token)   File "myproject\allauth\socialaccount\providers\facebook\views.py", line 43, in complete_login
    return fb_complete_login(request, app, access_token)   File "myproject\allauth\socialaccount\providers\facebook\views.py", line 31, in fb_complete_login
    .sociallogin_from_response(request, extra_data)   File "myproject\allauth\socialaccount\providers\base.py", line 44, in sociallogin_from_response
    adapter = get_adapter()   File "myproject\allauth\socialaccount\adapter.py", line 150, in get_adapter
    return import_attribute(app_settings.ADAPTER)()   File "myproject\allauth\utils.py", line 97, in import_attribute
    ret = getattr(importlib.import_module(pkg), attr) AttributeError: 'module' object has no attribute 'MySocialAccountAdapter' [17/Jul/2014 11:49:46] "GET /myproject/accounts2/facebook/login/callback/?code=AQBShGWTHnGVvlo-fOVW7xjF9RUJo-k7P23zISHC70p aAR5uWYpnI46gpHFUCC5Rz-SviDyTITVRAUkZ-DhkZaHyBT2n5UBhhSwkACgCKTTgPrFLAZFBQs05AEZ67xfk-wRlF47DSjT26bbDdUmc1ptfFxP3W4qS5Y6b5Yrj iLTI3RMScOEM0EKUQjNySyj4XSAVk6wj4HcAbCVxiVv5QaH63ayxyt5Y5jQ0AOH3zsCngPaqFNJArXseMS6wfqSc8yDwcwWZKo1nGhcNtA9Gy_bqZNiTZSjPJguhT lBwbmDAJ9SUNI8AS3yzC-AKDtD2_bo&state=441rn77wUuLH HTTP/1.1" 500 147978

Initially the socialadapter.py would not even compile,all others did compile even after deleting the .pyc I referred to this thread: pycompile for python3.2

and force compile but I still see the issue

Any suggestions on what I might be doing wrong here is greatly appreciated.

thank you for your valuable time.

-km

EDIT:

Environment

  • Python 2.7.5

  • allauth: 0.17

解决方案

Ok I figured out the issue , I had the settings entry for my adapter missing a the full path to the class. Now I am able to login using Facebook.

However I have another issue, I am trying to enable Linked in login for the same app and have the following entries in the settings

    SOCIALACCOUNT_PROVIDERS = \
{'linkedin':{'SCOPE': [ 'r_emailaddress',
                'r_fullprofile',
                'r_emailaddress',
                'r_contactinfo',
                'r_network'],
      'PROFILE_FIELDS':
            [
                'id',
                'first-name',
                'last-name',
                'email-address',
                'picture-url',
                'public-profile-url',
                'skills',
                'headline',
                'industry',
                'num-connections',
                'positions',
                'interests',
                'languages',
                'certifications',
                'educations',
                'courses',
                'three-current-positions',
                'three-past-positions',
                'recommendations-received',
                'honors-awards'
            ]
    },
 'facebook': {'SCOPE': ['email', 'user_about_me', 'user_birthday',
                            'user_education_history','user_work_history',
                            'user_hometown',
                            'user_location',
                            'user_religion_politics','user_subscriptions',
                            'read_stream',
                            'read_insights',
                            'read_friendlists',
                            'user_likes',
                            'user_interests',
                            'user_groups'
                            ],
                  'AUTH_PARAMS': {},
                  'METHOD': 'oauth2'
                },
}

Now When I use the login page, I get the following error

[17/Jul/2014 22:26:28] "GET /myproject/accounts2/linkedin/login/?process=connect HTTP/1.1" 302 0
ERROR:django.request:Internal Server Error: /myproject/accounts2/linkedin/login/callback/
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "myproject\allauth\socialaccount\providers\oauth\views.py", line 35, in view
    return self.dispatch(request, *args, **kwargs)
  File "myproject\allauth\socialaccount\providers\oauth\views.py", line 90, in dispatch
    return complete_social_login(request, login)
  File "myproject\allauth\socialaccount\helpers.py", line 113, in complete_social_login
    sociallogin=sociallogin)
  File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "myproject\allauth\socialaccount\socialadapter.py", line 50, in link_to_local_user
    email_address = sociallogin.account.extra_data['email']
KeyError: 'email'
[17/Jul/2014 22:26:50] "GET /myproject/accounts2/linkedin/login/callback/?oauth_token=77--d223fb8b-168f-4260-b93c-1a6e5ff2
e1e1&oauth_verifier=52724 HTTP/1.1" 500 139897

I am not sure how to fix this because the SCOPE for LinkedIn has : 'email-address', how can I fix this issue as the Email Fields in LinkedIn Documentation also says email-address

LinkedIn fields

Any suggestions are appreciated.

I am sorry I do not know how to put a bounty on the question and I do not have enough to place for the question also.

TIA

-km

这篇关于django allauth社会认证检索电子邮件与现有用户的电子邮件相匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆