Smfony2:HWIOauthBundle:使用多个语言环境
Smfony2 : HWIOauthBundle : Using multiple locales
我在我的 Symfony2 项目中实现了 HWIOauhBundle。除了使用不同的语言环境外,一切正常。我的默认语言环境是 "fr"。登录和使用 "en" 语言环境时,连接工作正常,但我被重定向到对应于 "fr" 语言环境的主页(主页是 default_target_path ).我只用google登录。
有什么建议吗?
我的配置如下:
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
app/config/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
app/config/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 开发者控制台:重定向 URI
http://myhost/web/app_dev.php/connect/service/google
http://myhost/web/app_dev.php/login/check-google
解决方法很简单。它只需要在每个路由和每个重定向 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 开发者控制台:重定向 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
我在我的 Symfony2 项目中实现了 HWIOauhBundle。除了使用不同的语言环境外,一切正常。我的默认语言环境是 "fr"。登录和使用 "en" 语言环境时,连接工作正常,但我被重定向到对应于 "fr" 语言环境的主页(主页是 default_target_path ).我只用google登录。
有什么建议吗?
我的配置如下:
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
app/config/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
app/config/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 开发者控制台:重定向 URI
http://myhost/web/app_dev.php/connect/service/google
http://myhost/web/app_dev.php/login/check-google
解决方法很简单。它只需要在每个路由和每个重定向 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 开发者控制台:重定向 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