我在Symfony2项目中实现了HWIOauhBundle。除了使用不同的语言环境外,一切正常。我的默认语言环境是“fr”。当记录并使用“en”语言环境时,连接工作正常但我被重定向到对应于“fr”语言环境的主页(主页是 default_target_path )。我只使用谷歌登录。
任何提案?
我的配置如下:
app / config / routing.yml:
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /{_locale}/connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /{_locale}/login-oauth
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /{_locale}/connect
google_login:
pattern: /login/check-google
应用/配置/ config.yml
# HWIOauth Configuration
hwi_oauth:
#
firewall_name: main
resource_owners:
google:
type: google
client_id: xxxxxxxxx
client_secret: yyyyyyyyy
scope: "email profile"
fosub:
# try 30 times to check if a username is available (foo, foo1, foo2 etc)
username_iterations: 30
# mapping between resource owners and properties
properties:
google: googleId
connect:
confirmation: true
应用/配置/ security.yml
security:
encoders:
My\UserBundle\Entity\User: sha512
role_hierarchy:
ROLE_ADMIN: [ROLE_AUTEUR, ROLE_MODERATEUR]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
anonymous: true
#provider: hwi
provider: fos_userbundle
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
default_target_path: mybundle_homepage
csrf_provider: form.csrf_provider
logout:
path: fos_user_security_logout
target: mybundle_homepage
handlers: [mybundle.logout_handler]
remember_me:
key: %secret%
lifetime: 31536000
oauth:
resource_owners:
google: google_login
login_path: hwi_oauth_connect
use_forward: false
failure_path: hwi_oauth_connect
default_target_path: mybundle_homepage
oauth_user_provider:
service: mybundle_user.provider.fosub_bridge
access_control:
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
Google Developpers Console:重定向URI
http://myhost/web/app_dev.php/connect/service/google
http://myhost/web/app_dev.php/login/check-google
答案 0 :(得分:1)
解决方案非常简单。它只需要在每个路由和每个重定向URI中引入区域设置。
app / config / routing.yml:
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /{_locale}/connect
requirements:
_locale: en|fr
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /{_locale}/login-oauth
requirements:
_locale: en|fr
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /{_locale}/connect
requirements:
_locale: en|fr
Google Developpers Console:重定向URI
http://myhost/web/app_dev.php/fr/connect/service/google
http://myhost/web/app_dev.php/en/connect/service/google
http://myhost/web/app_dev.php/fr/login/check-google
http://myhost/web/app_dev.php/en/login/check-google