【问题标题】:ApiPlatform + JwtAuthenticationBundleApiPlatform + JwtAuthenticationBundle
【发布时间】:2018-01-06 12:03:12
【问题描述】:

我正在尝试在没有 FOSUserBundle 的 Symfony 4 应用程序之上使用 JwtAuthenticationBundle 配置 api 平台。

我希望能够使用swagger界面。

# config/packages/api_platform.yaml
api_platform:
    swagger:
        api_keys:
            - { name: 'Authorization', type: 'header' }
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']

还有我的安全文件:

# config/packages/security.yaml
security:
    encoders:
        App\Entity\User:
            algorithm: bcrypt

    providers:
        db_provider:
            entity:
                class: App\Entity\User
                property: username
    firewalls:
        login:
            pattern:  ^/api/login
            stateless: true
            anonymous: true
            provider: db_provider
            form_login:
                check_path: /api/login_check
                username_parameter: _username
                password_parameter: _password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
                require_previous_session: false

        main:
            pattern:   ^/api
            provider: db_provider
            stateless: true
            anonymous: true
            lexik_jwt: ~

        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false


    access_control:
        - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }

如果我关注doc,我将看不到我的招摇页面,我有一个 401 - /api 上的凭据错误。我无法通过招摇 UI 上的“授权”按钮登录。 我必须在访问控制部分替换:- { path: ^/, roles: [ ROLE_READER ] }- { path: ^/, roles: [ IS_AUTHENTICATED_ANONYMOUSLY ] } 这样做。

我不知道我是否错过了/错过配置某些内容,或者文档中是否有错误

谢谢!

【问题讨论】:

    标签: symfony4 api-platform.com lexikjwtauthbundle


    【解决方案1】:

    我发现的唯一方法是修改 access_control,在第二个路径中添加一个斜杠:

    access_control:
            - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/api/,       roles: IS_AUTHENTICATED_FULLY }
    

    【讨论】:

      猜你喜欢
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 2022-11-10
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多