本文介绍了Smfony2:HWIOauthBundle:使用多个语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Symfony2项目中实现了HWIOauhBundle.除了使用不同的语言环境之外,其他所有东西都可以正常工作.我的默认语言环境是"fr".登录并使用"en"语言环境时,连接正常,但我被重定向到与"fr"语言环境相对应的主页(该主页为 default_target_path ).我只使用Google登录名.

I have implemented HWIOauhBundle in my Symfony2 project. Everything works fine except the use of different locales. My default locale is "fr". When logging and using "en" locale, the connexion works fine but I am redirected to the homepage corresponding to "fr" locale (the homepage is the default_target_path). I only use google login.

有没有建议?

我的配置如下:

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中引入区域设置即可.

The solution is quite simple. It just requires to introduce locale in each route and each redirect 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

这篇关于Smfony2:HWIOauthBundle:使用多个语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:11