Domanda

I need to ask different permission at facebook login:

  • publish_stream and emails for standard users
  • publish_stream, emails and manage_pages for "admin" users

Here, the library's author tell that I have to define a new backend/provider. But how can I do that?

I don't understand how can I do that. Can someone explain me what I've to do step-by-step?

È stato utile?

Soluzione

A backend like this should do the work:

from social_auth.backends.facebook import FacebookAuth, FacebookBackend

class FacebookBackendForAdmins(FacebookBackend):
    name = 'facebook-admins'

class FacebookAuthForAdmins(FacebookAuth):
    AUTH_BACKEND = FacebookBackendForAdmins
    SCOPE_VAR_NAME = 'FACEBOOK_ADMIN_EXTENDED_PERMISSIONS'

Then define the setting:

FACEBOOK_ADMIN_EXTENDED_PERMISSIONS = ['email', 'publish_stream', 'manage_pages']

And don't forget the setting for non-admin users:

FACEBOOK_EXTENDED_PERMISSIONS = ['email', 'publish_stream']

And also add it to AUTHENTICATION_BACKENDS setting (assuming that you add that code into yourapp/facebook_backend_for_admins.py):

AUTHENTICATION_BACKENDS = (
    ...
    'yourapp.facebook_backend_for_admins.FacebookBackendForAdmins',
    ...
)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top