Skip to content

Commit

Permalink
Fix FB logins (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldpbear authored May 12, 2018
1 parent 88ca139 commit 192617e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@
# See http://django-social-auth.readthedocs.org/en/latest/configuration.html
# for list of available backends.
'social.backends.twitter.TwitterOAuth',
'social.backends.facebook.FacebookOAuth2',
#'social.backends.facebook.FacebookOAuth2',
'sa_api_v2.auth_backends.NoRedirectStateFacebookOAuth2',
'social.backends.google.GoogleOAuth2',
'sa_api_v2.auth_backends.CachedModelBackend',
)
Expand Down
9 changes: 9 additions & 0 deletions src/sa_api_v2/auth_backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth.backends import ModelBackend
from .cache import UserCache
from social.backends.facebook import FacebookOAuth2

class CachedModelBackend (ModelBackend):
def get_user(self, user_id):
Expand All @@ -8,3 +9,11 @@ def get_user(self, user_id):
user = super(CachedModelBackend, self).get_user(user_id)
UserCache.set_instance(user, user_id=user_id)
return user

# This custom backend prevents the dynamic redirect_state query param from
# being sent with FB OAuth requests. redirect_state interferes with upgraded
# FB security requirements.
# https://stackoverflow.com/questions/45307723/valid-oauth-redirect-uris-for-facebook-django-social-auth
# https://developers.facebook.com/docs/facebook-login/security/#surfacearea
class NoRedirectStateFacebookOAuth2(FacebookOAuth2):
REDIRECT_STATE = False

0 comments on commit 192617e

Please sign in to comment.