Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore default HTML redirect on facebook app backend
- Loading branch information
Showing
1 changed file
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |