douhan1860 2015-07-16 20:06
浏览 41
已采纳

使用HWIOAuthBundle登录Facebook后,区域设置回退到默认值

I have a problem, that when I switch the language on my site, and I do a Facebook Login using HWIOAuthBundle, I always get redirect to the default locale, what I set in the config.yml. (in my case: "en")

routing.yml

# Facebook Connect 
hwi_oauth_security:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /{_locale}/login
    defaults: { _locale: en }
    requirements:
        _locale: en|de

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
    prefix:   /{_locale}/login
    defaults: { _locale: en }
    requirements:
        _locale: en|de

hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /{_locale}/login
    defaults: { _locale: en }
    requirements:
        _locale: en|de

facebook_login:
    path: /{_locale}/login/check-facebook
    defaults: { _locale: en }
requirements:
    _locale: en|de

# Site Routing #
homepage:
    path:     /{_locale}
    defaults: { _controller: MyPageBundle:Homepage:index, _locale: en }
    requirements:
        _locale: en|de

oauth firewall settings in security.xml

 firewalls:
        main:
            oauth:
                resource_owners:
                    facebook: "/%locale%/login/check-facebook"
                login_path: fos_user_security_login
                failure_path: fos_user_security_login
                oauth_user_provider:
                    service: hwi_oauth_user_provider
                always_use_default_target_path: true
                default_target_path: "/%locale%"

After that when I open the mysite.com/en/login/facebook, I get successfully logged in with my facebook account and get redirect to the following link: mysite.com/en#_=_

But when I open mysite.com/de/login/facebook, I get redirect to the same url like in the previous case. It seems that the locale doesn't get passed after the redirection and fallbacks to the default locale.

In every other case the locale works fine. For example I'm using FOSUserBundle and after login, logout or signup I get redirect with the correct locale every time.

Could someone help me to solve this problem? Thank you in advance!

  • 写回答

1条回答 默认 最新

  • douzhi1813 2015-07-21 06:51
    关注

    Okay I found the source of the problem. I used the %locale% variable in my facebook resource_owners which is not the same as the _locale variable but it is the locale variable in my parameters.yml. So I solved my problem with the following modifications:

    After that I received a No resource owner with name 'check-facebook' error message, but I solved it by deleting every _locale related things from the facebook-login route:

    facebook_login:
        path: /login/check-facebook
    

    I hope it will helps to others too :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测