Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-social-auth redirect_uri invalid

I've been banging my head against the wall trying to get django-social-auth working. My dev server is a server in a private network at my work, accessed by a 10.0.0.* IP Address. We have multiple django apps running on this server. Here's the config I have for this app:

# Perceptual
location /perceptual/static/ {
        alias /opt/perceptual/perceptual/static/;
}
location /perceptual/ {
        proxy_pass http://127.0.0.1:8001;
}

I'm running a backbone.js app out of my static directory with this. So, I can go to 10.0.0.54/perceptual/static/, and get my backbone app.

NOW, I have my Facebook APP_ID and FACEBOOK_API_SECRET in my settings file, all correctly configured. I also have a line in my /etc/hosts file on my actual machine (not the dev server) that directs myapp.com to 10.0.0.54, and my Facebook app config for the App Domains and Site URL look like this:

App Domains: perceptual.com
Site URL: http://perceptual.com

The problem is, whenever I go to perceptual.com/perceptual/static/login/facebook/ it gives me this error: Facebook Error (django-social-auth)

Here's what my URL looks like when I get that error: https://www.facebook.com/dialog/oauth?scope=email&state=PC0OhXnEuaW2wcUuINO0rMSMAtVDuMbn&redirect_uri=http%3A%2F%2F127.0.0.1%3A8001%2Fperceptual%2Fcomplete%2Ffacebook%2F%3Fredirect_state%3DPC0OhXnEuaW2wcUuINO0rMSMAtVDuMbn&client_id=419178148154217

So you can see from the URL that my redirect_uri is http://localhost:8001 - But I don't want it to be that, obviously. As soon as I change it to perceptual.com, it gets a bit farther: Then I get this error:

AuthFailed at /perceptual/complete/facebook/
Authentication failed: There was an error authenticating the app

Here's my traceback, if it helps

At this point, I'm stuck - How do I get my server to change the redirect_uri to something that Facebook can handle, instead of 127.0.0.1:8000? My guess is that it's coming from Django, but I'm not sure how to change it. Then, once that's fixed, it still can't fully authenticate, and gets the error stated above. Any help would be greatly appreciated. Thanks so much!

like image 707
James Rasmussen Avatar asked Dec 08 '12 23:12

James Rasmussen


1 Answers

django-social-auth uses request.build_absolute_uri() to build that redirect_uri parameter. Checking django code for build_absolute_uri() it calls get_host() which checks for HTTP_X_FORWARDED_HOST, HTTP_HOST or SERVER_NAME.

Try defining any of those headers in your location recipe (I think there's a proxy_set_header for that).

like image 127
omab Avatar answered Nov 19 '22 19:11

omab