简体   繁体   English

在Django中通过OpenID身份验证获取Google联系人

[英]Obtain Google Contacts via OpenID Authentication in Django

I am using the Django package django_openid_auth and this snippet of code to authenticate a user in Django via his OpenID. 我正在使用Django包django_openid_auth和此代码段通过Django的OpenID对用户进行身份验证。

This works perfectly. 这很完美。 The user is redirected to the Google Accounts page to obtain the permission, then is redirected back. 将用户重定向到Google帐户页面以获取权限,然后将其重定向回。

However, this only servers to obtain the user's email/fist name/last name. 但是,这仅用于获取用户的电子邮件地址/拳头名称/姓氏。 If I want to obtain the list of contacts of the user, or even sensible information such as date of birth or avatar, how does that work? 如果我想获取用户的联系人列表,甚至获取诸如出生日期或头像等明智信息,那该如何工作?

I assume that, since I'm obtaining the email/names via the OpenID AX extension, I can similarly obtain OAuth information using the Ext2 extension? 我假设,因为我是通过OpenID AX扩展名获取电子邮件/名称的,所以我可以类似地使用Ext2扩展名来获取OAuth信息吗?

I know the Google Contacts API needs OAuth authentication. 我知道Google联系人API需要OAuth身份验证。 Since I'm signing in with OpenID, is this OAuth authentication included, or must I do it in a new separate process? 由于我使用OpenID登录,因此该OAuth身份验证是否包括在内,还是必须在新的单独流程中进行? So in short, is this OpenID authentication including the authentication process for obtaining contacts/account info, or must I authenticate and use a separate process? 简而言之,此OpenID身份验证是否包括用于获取联系人/帐户信息的身份验证过程,还是我必须进行身份验证并使用单独的过程?

The internal mechanics of the OpenID mechanism used are in the django_openid_auth module. 所使用的OpenID机制​​的内部机制位于django_openid_auth模块中。

Can somebody point me in the right direction? 有人可以指出我正确的方向吗? Thank you. 谢谢。

I think you should think about using OAuth2 instead of the hybrid of OpenID2 and OAuth 1. It is possible to do it with the latter, but it's MUCH easier to use OAuth2. 我认为您应该考虑使用OAuth2,而不是使用OpenID2和OAuth 1的混合体。可以用后者来实现,但是使用OAuth2更容易。 I'm not up on specific OAuth2 libraries for Django, but the Python OAuth2 library that Google has authored is 'state of the art'. 我没有使用针对Django的特定OAuth2库,但Google编写的Python OAuth2库是“最新技术”。 It even has info on using it with Django 它甚至包含有关在Django上使用它的信息

https://developers.google.com/api-client-library/python/guide/aaa_oauth https://developers.google.com/api-client-library/python/guide/aaa_oauth

This library will let you ask for the contacts scope, as well as the userinfo.profile scope that you are interested in. 该库可让您询问联系人范围以及您感兴趣的userinfo.profile范围。

hope this helps. 希望这可以帮助。

davep 戴维普

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM