本文介绍了django-social-auth redirect_uri无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直把头撞在墙上,试图让django-social-auth工作。我的开发服务器是我的工作中的私有网络中的服务器,由10.0.0。* IP地址访问。我们在这台服务器上运行多个django应用程序。这是我为这个应用程序配置:

 #感知
位置/感知/静态/ {
别名/ opt /感知/感知/静态/;
}
位置/感知/ {
proxy_pass http://127.0.0.1:8001;
}

我正在使用我的静态目录中的backbone.js应用程序。所以,我可以去10.0.0.54/perceptual/static/,并得到我的骨干应用程序。



现在,我的设置文件中的Facebook APP_ID和FACEBOOK_API_SECRET都已正确配置。我还在我的实际机器(而不是开发服务器)的/ etc / hosts文件中有一行,将 myapp.com 指向 10.0.0.54 ,我的Facebook应用程序配置的应用程序域和网站URL如下所示:

 应用程序域:perceptual.com 
网站URL:http://perceptual.com

问题是,每当我去perceptual.com/perceptual/static/login/facebook/它给我这个错误:



这是我的网址看起来像我的错误:



所以你可以从URL中看到我的redirect_uri是 http:// localhost:8001 - 但是我不希望它是这样的。一旦我更改为perceptual.com,它会变得更远一点:然后我得到这个错误:

  AuthFailed at /感知/完成/ facebook / 
身份验证失败:认证应用程序发生错误

我的



此时我被卡住了 - 如何让我的服务器将redirect_uri更改为Facebook可以处理的内容,而不是127.0.0.1:8000?我的猜测是来自Django,但我不知道如何改变它。然后,一旦固定,它仍然无法完全验证,并得到上述错误。任何帮助将不胜感激。非常感谢!

解决方案

django-social-auth使用 request.build_absolute_uri()来构建 redirect_uri 参数。检查它调用,它检查 HTTP_X_FORWARDED_HOST HTTP_HOST SERVER_NAME



尝试在您的位置食谱中定义任何这些标题(我认为有一个 proxy_set_header


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:

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!

解决方案

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

这篇关于django-social-auth redirect_uri无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 16:49