【问题标题】:HWIOAuthBundle without FOSUserBundle没有 FOSUserBundle 的 HWIOAuthBundle
【发布时间】:2018-03-14 19:38:18
【问题描述】:

我在使用具有自定义身份验证(不使用 FOSUserBundle)的当前应用程序为 google 登录/注册实现 HWIOAuthBundle 时遇到问题。

首先,我在尝试连接到“xxxx/connect/google”时遇到 404 错误。在哪里可以看到列出的 HWIOAuthBundle 路径,可以在我的 twig 文件中使用?

登录树枝:

<a href="{{ path('hwi_oauth_service_redirect', {'service' : 'google'}) }}" 
    class="google-login">Google</a>

routing.yml:

google_login:
    path: /login/check-google

hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /connect

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
    prefix:   /connect

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /login

config.yml

hwi_oauth:
    firewall_names: [main]
    resource_owners:
        google:
            type:                google
            client_id:           ?
            client_secret:       ?
            scope:               "email profile"

security.yml:

security:
    providers:
        db_provider:
            entity:
                class: AppBundle:User
                property: email
        my_custom_hwi_provider:
            id: ib_user.oauth_user_provider
    firewalls:
        main:
            oauth:
                resource_owners:
                    google: "/login/check-google"
                login_path: /login
                failure_path: /login
                oauth_user_provider:
                    service: ib_user.oauth_user_provider

用户.php:

class User extends OAuthUser implements UserInterface {
    //added googleId attribute and setters/getter
    //also added the "extends OAuthUser"
}

OAuthProvider.php 也是我新增的一个类。

【问题讨论】:

  • bin/console debug:router 应该显示可用的路由。
  • 如何获得需要重定向到谷歌的 HWIOAuth 路由。我以为我在 routing.yml 上导入了它?

标签: php symfony authentication google-plus-signin hwioauthbundle


【解决方案1】:

正如第一条评论所说,调试路由命令是:

php bin/console debug:router

一个问题可能是 security.yml 中缺少连接的访问​​控制路径:

access_control:
    - { path: ^/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }

【讨论】:

  • 我在使用 Auth0 时也遇到了这个问题。使用 ^/connect 规则更新 security.yaml 修复了重定向。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-31
  • 1970-01-01
  • 1970-01-01
  • 2015-05-18
相关资源
最近更新 更多