Skip to content

Commit

Permalink
Restore default HTML redirect on facebook app backend
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Aug 30, 2013
1 parent 24d96e9 commit a282469
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions social_auth/backends/facebook.py
@@ -1,8 +1,41 @@
from django.conf import settings
from django.template import TemplateDoesNotExist


# TODO: review HTML rendering in facebook app backend
if getattr(settings, 'FACEBOOK_APP_AUTH', False):
from social.backends.facebook import FacebookAppOAuth2 as FacebookBackend
from social.backends.facebook import \
FacebookAppOAuth2 as FacebookBackendBase
else:
from social.backends.facebook import FacebookOAuth2 as FacebookBackend
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)

0 comments on commit a282469

Please sign in to comment.