<commit_before>from django.conf import settings


# TODO: review HTML rendering in facebook app backend
if getattr(settings, 'FACEBOOK_APP_AUTH', False):
    from social.backends.facebook import FacebookAppOAuth2 as FacebookBackend
else:
    from social.backends.facebook import FacebookOAuth2 as FacebookBackend<commit_msg>Restore default HTML redirect on facebook app backend<commit_after>from django.conf import settings
from django.template import TemplateDoesNotExist


if getattr(settings, 'FACEBOOK_APP_AUTH', False):
    from social.backends.facebook import \
            FacebookAppOAuth2 as FacebookBackendBase
else:
    from social.backends.facebook import FacebookOAuth2 as FacebookBackendBase


REDIRECT_HTML = """
<script type="text/javascript">
    var domain = 'https://apps.facebook.com/',
        redirectURI = domain + '{{ FACEBOOK_APP_NAMESPACE }}' + '/';
    window.top.location = 'https://www.facebook.com/dialog/oauth/' +
    '?client_id={{ FACEBOOK_KEY }}' +
    '&redirect_uri=' + encodeURIComponent(redirectURI) +
    '&scope={{ FACEBOOK_EXTENDED_PERMISSIONS }}';
</script>
"""


class FacebookBackend(FacebookBackendBase):
    def auth_html(self):
        key, secret = self.get_key_and_secret()
        namespace = self.setting('NAMESPACE', None)
        scope = self.get_scope()
        if scope:
            scope = self.SCOPE_SEPARATOR.join(scope)
        ctx = {
            'FACEBOOK_APP_NAMESPACE': namespace or key,
            'FACEBOOK_KEY': key,
            'FACEBOOK_EXTENDED_PERMISSIONS': scope,
            'FACEBOOK_COMPLETE_URI': self.redirect_uri,
        }
        tpl = self.setting('LOCAL_HTML', 'facebook.html')
        try:
            return self.strategy.render_html(tpl=tpl, context=ctx)
        except TemplateDoesNotExist:
            return self.strategy.render_html(html=REDIRECT_HTML, context=ctx)
{'fraction_non_alphanumeric': 0.10194174757281553, 'fraction_numerical': 0.002157497303128371, 'mean_word_length': 3.5354523227383865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4130151', 'n_tokens_mistral': 550, 'n_tokens_neox': 556, 'n_words': 117}