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!
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:
facebook resource_owners
to facebook-login
route. 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 :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.