How can I ask for different permissions from facebook at different times?

Facebook recommends that when using facebook login you should first ask the user for as few permissions as possible and, in particular, avoid asking for permission to be published until the user has to publish something through your website - https: //developers.facebook. com / docs / facebook-login / permissions / # optimizing .

We tried to implement this using the python-social-auth django application, but it seems that there is no way to request different permissions at different points of the site - the area is set using the parameter SOCIAL_AUTH_FACEBOOK_SCOPEand in the future it is impossible to request another area (for example, excluding publish_actionsfrom SOCIAL_AUTH_FACEBOOK_SCOPE), and then ask user to grant this permission when trying to send from your website to facebook).

Does anyone know if this is possible in a python-social-auth application, and if so, how?

+4
source share
1 answer

(The following text was extracted from documents at http://psa.matiasaguirre.net/docs/use_cases.html#multiple-scopes-per-provider )

python-social-auth , , , . , , , .

get_scope()

from social.backends.facebook import FacebookOAuth2


class CustomFacebookOAuth2(FacebookOauth2):
    def get_scope(self):
        scope = super(CustomFacebookOAuth2, self).get_scope()
        if self.data.get('extrascope'):
            scope += [('foo', 'bar')]
        return scope

, , (get_scope()) , , GET POST (self.data).

- FacebookOAuth2 AUTHENTICATION_BACKENDS .

, , , , URL-, ( ) , URL- . , :

from social.backends.facebook import FacebookOAuth2


class CustomFacebookOAuth2(FacebookOauth2):
    name = 'facebook-custom'

- , FacebookOAuth2 AUTHENTICATION_BACKENDS. URL-:

/login/facebook-custom
/complete/facebook-custom
/disconnect/facebook-custom

:

SOCIAL_AUTH_FACEBOOK_CUSTOM_KEY = '...'
SOCIAL_AUTH_FACEBOOK_CUSTOM_SECRET = '...'
SOCIAL_AUTH_FACEBOOK_CUSTOM_SCOPE = [...]

, /login/facebook-custom, auth user.social_auth.get(provider='facebook-custom') access_token .

+4

Source: https://habr.com/ru/post/1532127/


All Articles