django-socialregistration
django-socialregistration copied to clipboard
Add ability to request OpenID attributes such as email_address
Hello! I'm working with your library, and the basics seem to be working smoothly!
However, I'd really prefer to request that the OpenID provider pass on the customer's basic data at least, like this (inserted into get_redirect, in utils.py):
from openid.extensions import sreg
sreg_request = sreg.SRegRequest(required=['nickname'], optional=['fullname', 'email'])
auth_request.addExtension(sreg_request)
Ideally, a config param set:
SOCIALREGISTRATION_OPENID_REQUEST_ATTRIBUTES=True
SOCIALREGISTRATION_OPENID_REQUIRED_ATTRIBUTES=['nickname']
SOCIALREGISTRATION_OPENID_OPTIONAL_ATTRIBUTES=['fullname','email']
Thanks!
Tim
does this works? do you know how to do the same with facebook? thx
For the above code to work, I added something like this on /socialregistration/views.py/openid_callback():
if client.is_valid():
from openid.extensions import sreg
resp = sreg.SRegResponse.fromSuccessResponse(client.result)
if resp:
print '==> nickname', resp.get('nickname', '')
print '==> fullname', resp.get('fullname', '')
print '==> email', resp.get('email', '')
else:
print '==> No OpenID->Simple Regisration support!'
Note: I'm still looking how to do that on my own app, not on django-socialregistration itself.
Please note that not all OpenID-capable sites support Simple Registration as explained here: http://stackoverflow.com/questions/2264669/how-do-i-get-the-username-and-email-when-someono-login-my-site-use-google-openid
To get same from Facebook? Try the following on your views.py :
graph = request.facebook.graph
fb_profile = graph.get_object("me")
first_name = fb_profile['first_name']
last_name = fb_profile['last_name']
For reference, look here http://developers.facebook.com/docs/reference/api/user
thanks that was very useful, espacially for facebook, it works great. For openid, i finally don't like the sreg method since it doesn't work with google. socialregistration working with django-openid doesn't support Attribute Exchange AX i suppose?
vallettea, so to retrieve facebook user's name and e-mail what do I have to do?
sorry for the delay francis, to get email and user's name from facebook, I had to modifiy the code of the views of social_registration (dirty i know) adding graph = request.facebook.graph fb_profile = graph.get_object("me") first_name = fb_profile['first_name'] last_name = fb_profile['last_name'] email = fb_profile['email']
in the facebook_login function
Hi, thank you very much. I was able to get the first and last name, but the email is an unknown key, as there isn't any. How did you get the email permissions?
they are asked by the popup window that asks the user if he accepts to sign in and give his infos
+1 This would be extremely useful.
this exchange helps with facebook but it seems there is still no solution to retreive the email from google. Does anyone has some new hints about the subject?
in utils.py in OpenID(object)
URLS = {
'ax_email': 'http://axschema.org/contact/email',
'ax_first': 'http://axschema.org/namePerson/first',
'ax_last': 'http://axschema.org/namePerson/last',
}
def get_redirect(self):
auth_request = self.consumer.begin(self.endpoint)
ax_request = ax.FetchRequest()
ax_request.add(ax.AttrInfo(URLS['ax_email'], required = True))
ax_request.add(ax.AttrInfo(URLS['ax_first'], required = True))
ax_request.add(ax.AttrInfo(URLS['ax_last'], required = True))
auth_request.addExtension(ax_request)
and in views.py in def openid_callback(...)
if client.is_valid():
identity = client.result.identity_url
email = first_name = last_name = None
ax_response = ax.FetchResponse.fromSuccessResponse(client.result)
email = ax_response.getSingle('http://axschema.org/contact/email', email)
first_name = ax_response.getSingle('http://axschema.org/namePerson/first', first_name)
last_name = ax_response.getSingle('http://axschema.org/namePerson/last', last_name)
also import in both files from openid.extensions import ax
and that's that.
Guys, has there been any movement on this topic? Im really keep to use socialreg for a large company but the need to specify required user info is paramount? I'd appreciate any news you could provide :)