Задать вопрос

Тел: +7 965 3737 888

463

Просмотров

12

Ответов

Facebook Authentication Backend

Authentication through Facebook's Graph API. See

http://developers.facebook.com/docs/authentication/ http://developers.facebook.com/docs/authentication/permissions http://developers.facebook.com/docs/api http://github.com/facebook/python-sdk/blob/master/examples/oauth/facebookoauth.py

Define the facebook tokens in settings.py and replace <app_name> with the name of your app. You will probably want to modify the scope on the authorize link in the template, see the authentication permissions link.

This updates the user model every time the user logs in but I think that it is okay so the data is always correct. I have tested this but not rigorously. If there is a hole and everyone gets admin rights to your site don't say I didn't warn you :).

Comments are appreciated.

16 June 2010 Added missing imports. Cleaned up the template.

Shouts out to @obeattie and @whalesalad

Вопрос полезен? Да0/Нет0
file_4774.py(5.8Кб)
None

Ответы (12):

Ответamit:27.09.2012
Ответ полезен? Да0/Нет0

Great example for beginners like me. can you submit the client code as well, the request content is not clear to me. e.g. I didn't figure out the request's 'code' field value used in: if 'code' in request.GET: args = { 'client_id': settings.FACEBOOK_APP_ID, 'redirect_uri': settings.FACEBOOK_REDIRECT_URI, 'client_secret': settings.FACEBOOK_API_SECRET, 'code': request.GET['code'], }

10x!

Ответnxvl:09.01.2012
Ответ полезен? Да0/Нет0

Sorry, Markdown failed on me, add this 2 lines to FacebookBackend class:

supports_object_permissions=True 
supports_anonymous_user=False

Ответnxvl:09.01.2012
Ответ полезен? Да0/Нет0

I have, you need to make a small change:

class FacebookBackend: + supports_object_permissions=True + supports_anonymous_user=False

and it will work.

Ответethan.l.whitt:03.12.2011
Ответ полезен? Да0/Нет0

Has anyone tried this with Django 1.3 ?

Ответfrantzdyromain:29.09.2011
Ответ полезен? Да0/Нет0

@aisay I am just picking up on Django how is it a security hole.

Ответaisay:18.08.2011
Ответ полезен? Да0/Нет0

Hi all! Here is a security hole in this snippet: user = auth_models.User.objects.get(username=profile['id'])

username=profile['id'] can be existed user with grand access.

I think the best would be write:

user = facebook_session.user or User(username=profile['id'])

Thanks!

Ответdiehell:17.08.2010
Ответ полезен? Да0/Нет0

Barnardo,

Im new django using embarking on my first project making an fb app using django. Will use this for my project. Thanks.

How do i get hold of you on help with django & fb??

Ответbarnardo:22.07.2010
Ответ полезен? Да0/Нет0

Graph is now the official API. The REST one has been deprecated. Not sure about Google Apps, been meaning to check the out.

Ответlightcatcher:19.07.2010
Ответ полезен? Да0/Нет0

very nice code, I'll probably be using that in my next facebook app, I don't know how well (or if) this can work with Google App Engine.

Leveraging the official facebook API code would be good though

Ответupas:13.07.2010
Ответ полезен? Да0/Нет0

I just wanted to say that I'm using this and it's awesome :D

Ответbarnardo:16.06.2010
Ответ полезен? Да0/Нет0

Thanks, I added them.

Ответbrooks_lt:15.06.2010
Ответ полезен? Да0/Нет0

I think you're missing some imports in the "views" section.