Search code examples
djangofacebook-authenticationpython-social-auth

Facebook Social Auth Login: Can't Load URL: The domain of this URL isn't included in the app's domains


I am developing a web application using Django and python-social-auth. I want users to login with Facebook.

I have this in my python settings:

SOCIAL_AUTH_FACEBOOK_KEY = '...'
SOCIAL_AUTH_FACEBOOK_SECRET = '...'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

When my users enter the facebook page where they should provide credentials they see an error like this:

Can't Load URL: The domain of this URL isn't included in the app's domains.
To be able to load this URL, add all domains and subdomains of your 
app to the App Domains field in your app settings.

In Facebook for Developers dashboard I have added "Facebook Login" product and added redirect url:

http://localhost:8000/complete/facebook/

In settings, Website Site URL is set to: http://localhost:8000/ and App Domains is set to localhost.

What am I doing wrong?

BTW this is the url that my users see when the facebook page opens:

https://www.facebook.com/v2.9/dialog/oauth?scope=email&state=HSfkstGUR5028DMhUzfWOSgo6fpPx29E&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcomplete%2Ffacebook%2F%3Fredirect_state%3DHSfkstGUR5028DMhUzfWOSgo6fpPx29E&client_id=...&return_scopes=true

Solution

  • Disable the 'Use Strict Mode for Redirect URIs' setting in your Facebook login app.

    OR

    Note the redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcomplete%2Ffacebook%2F%3Fredirect_state%3DHSfkstGUR5028DMhUzfWOSgo6fpPx29E parameter of generated url.

    For some inexplicable reason Facebook requires Valid OAuth redirect URIs setting to be exactly the same as the redirect url.

    So use a tool like https://meyerweb.com/eric/tools/dencoder/, decode the url and set Valid OAuth redirect URIs to the full url. I.E:

    http://localhost:8000/complete/facebook/redirect_state=HSfkstGUR5028DMhUzfWOSgo6fpPA59E