Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

python - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...