def _get_oauth_session( self, redirect_uri: Optional[str] = None, scope: Optional[List[str]] = None, **kwargs, ) -> OAuth2Session: """ :param redirect_uri: The URL that you want to redirect the person logging in back to. :param scope: A list of permission string to request from the person using your app. :param kwargs: Additional parameters for oauth. :return: OAuth Session """ # check app credentials if not all([self.app_id, self.app_secret]): raise LibraryError({"message": "OAuth need your app credentials"}) if redirect_uri is None: redirect_uri = self.DEFAULT_REDIRECT_URI if scope is None: scope = self.DEFAULT_SCOPE session = OAuth2Session( client_id=self.app_id, scope=scope, redirect_uri=redirect_uri, state=self.STATE, **kwargs, ) session = facebook_compliance_fix(session) return session
def _get_oauth_session(self, redirect_uri=None, scope=None, **kwargs): """ build session for oauth flow. :param redirect_uri: The URL that you want to redirect the person logging in back to. :param scope: A list of Permissions to request from the person using your app. :param kwargs: Extend args for oauth. :return: """ if redirect_uri is None: redirect_uri = self.redirect_uri if scope is None: scope = self.scope session = OAuth2Session( client_id=self.app_id, scope=scope, redirect_uri=redirect_uri, state=self.DEFAULT_STATE, **kwargs ) session = facebook_compliance_fix(session) return session
def get_authorization_url(self, redirect_uri=None, scope=None, **kwargs): # type: (str, List, Dict) -> (str, str) """ Build authorization url to do authorize. Refer: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow :param redirect_uri: The URL that you want to redirect the person logging in back to. Note: Your redirect uri need be set to `Valid OAuth redirect URIs` items in App Dashboard. :param scope: A list of Permissions to request from the person using your app. :param kwargs: Extend args for oauth. :return: Authorization url and state. """ if not all([self.app_id, self.app_secret]): raise PyFacebookException( ErrorMessage( code=ErrorCode.MISSING_PARAMS, message="To do authorization need your app credentials")) if redirect_uri is None: redirect_uri = self.redirect_uri if scope is None: scope = self.scope session = OAuth2Session(client_id=self.app_id, scope=scope, redirect_uri=redirect_uri, state=self.DEFAULT_STATE, **kwargs) self.auth_session = facebook_compliance_fix(session) authorization_url, state = self.auth_session.authorization_url( url=self.authorization_url) return authorization_url, state
def init_oauth2_session(request): oauth2_session = OAuth2Session(settings.FACEBOOK_CLIENT_ID, redirect_uri='%s%s' % ('https://xb999.gondor.co', reverse('facebook_complete'))) oauth2_session = facebook_compliance_fix(oauth2_session) return oauth2_session