2

我正在尝试集成FOSUserBundleFOSOAuthServerBundle保护我RESTFul APIs,但在访问登录页面时出现以下错误,我对它很陌生,所以我不知道如何摆脱这个错误。

在这里,我正在尝试打开一个登录表单,FOSUserBundle以便我可以登录并获取令牌

在此处输入图像描述

这是我的security.yml

# FOR FOSUserBundle 

security:

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    encoders:
        "FOS\UserBundle\Model\UserInterface": sha512

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN


# FOR FOSOAuthServerBundle 

security:
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username
    firewalls:
        oauth_token:
            pattern:    ^/oauth/v2/token
            security:   false


        oauth_authorize:
            pattern:    ^/oauth/v2/auth
            form_login:
                 provider: fos_userbundle
                 check_path: /oauth/v2/auth/login_check
                 login_path: /oauth/v2/auth/login
            anonymous: true
            # Add your favorite authentication process here

        api:
            pattern:    ^/api
            fos_oauth:  true
            stateless:  true
            anonymous: true # can be omitted as its default value

    access_control:
           - { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }
4

2 回答 2

4

我相信你的 security.yml 应该是这样的:

security:
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    encoders:
        "FOS\UserBundle\Model\UserInterface": sha512

firewalls:
    oauth_token:
        pattern:    ^/oauth/v2/token
        security:   false


    oauth_authorize:
        pattern:    ^/oauth/v2/auth
        form_login:
             provider: fos_userbundle
             check_path: /oauth/v2/auth/login_check
             login_path: /oauth/v2/auth/login
        anonymous: true
        # Add your favorite authentication process here

    api:
        pattern:    ^/api
        fos_oauth:  true
        stateless:  true
        anonymous: true # can be omitted as its default value
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }
    - { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN
于 2013-10-17T18:46:06.840 回答
0

您将security通过稍后在配置文件中第二次添加密钥来覆盖您的第一个指令。

将两个配置(security.firewalls, security.access_control, ... )合并到一个security:指令中,你应该很高兴。

于 2013-10-17T18:45:45.240 回答