简体   繁体   English

使用HWIOAuthBundle登录Facebook后,语言环境回退到默认值

[英]Locale fallbacks to the default value after Facebook login using HWIOAuthBundle

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 . 我有一个问题,当我切换网站上的语言并使用HWIOAuthBundle进行Facebook登录时,我总是会重定向到默认的语言环境,即在config.yml设置的config.yml (in my case: "en") (就我而言:“ en”)

routing.yml 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 security.xml中的oauth防火墙设置

 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#_=_ 之后,当我打开mysite.com/en/login/facebook ,我成功使用我的facebook帐户登录并重定向到以下链接: mysite.com/en#_=_ _=_

But when I open mysite.com/de/login/facebook , I get redirect to the same url like in the previous case. 但是,当我打开mysite.com/de/login/facebook ,我将重定向到与前面的情况相同的URL。 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. 例如,我使用FOSUserBundle,登录,注销或注册后,每次都使用正确的语言环境进行重定向。

Could someone help me to solve this problem? 有人可以帮我解决这个问题吗? Thank you in advance! 先感谢您!

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 . 我在我的facebook resource_owners使用了%locale%变量,它与_locale变量不同,但是它是我的parameters.ymllocale变量。 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: 之后,我收到一个No resource owner with name 'check-facebook'No resource owner with name 'check-facebook'错误消息,但我通过从facebook-login路线中删除所有与_locale相关的内容来解决了该问题:

facebook_login:
    path: /login/check-facebook

I hope it will helps to others too :) 我希望它也对其他人有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM