超级管理员/auth-bundle

使用ApiPlatform和JWT的SuperAdmin Bundle

安装量: 2,398

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 3

分支: 0

公开问题: 0

类型:symfony-bundle

v1.4.1 2021-10-14 11:51 UTC

README

此包提供了与 Symfony 的简单集成,用于 SuperAdmin API。

您可以选择启动自己的 SuperAdmin 服务器 或者免费使用托管服务。

安装

从此包的 ~1.0 版本开始,只提供了实现类,配置和依赖项管理必须由用户完成(在此处文档化)。在未来的版本中,它将在包安装时自动完成。

依赖关系

composer require lexik/jwt-authentication-bundle

通过composer安装

composer require superadmin/auth-bundle ~1.0

配置

安装后,您必须将以下设置添加到您的配置文件中

# File config/packages/security.yaml

security:
    
    access_decision_manager:
        strategy: unanimous
        allow_if_all_abstain: false
    
    # https://symfony.com.cn/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        jwt:
            lexik_jwt:
                class: SuperAdmin\Bundle\Security\User

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

        main:
            pattern: ^/
            stateless: true
            anonymous: true
            provider: jwt
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
                    - SuperAdmin\Bundle\Security\Authenticator\ApiKeyAuthenticator
                entry_point: lexik_jwt_authentication.jwt_token_authenticator

            # activate different ways to authenticate
            # https://symfony.com.cn/doc/current/security.html#firewalls-authentication

            # https://symfony.com.cn/doc/current/security/impersonating_user.html
            # switch_user: true

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
        - { path: ^/docs, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/public, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/sadmin, roles: ROLE_SUPER_ADMIN }
        - { path: ^/admin, roles: ROLE_ADMIN }
        - { path: ^/, roles: ROLE_USER }
# File config/services.yaml

services:
    # here your original configurations
    # ...

    SuperAdmin\Bundle\Security\Authenticator\ApiKeyAuthenticator:
        arguments: [ '@doctrine.orm.entity_manager']

    SuperAdmin\Bundle\Security\Serializer\ContextBuilder:
        decorates: 'api_platform.serializer.context_builder'
        arguments: [ '@SuperAdmin\Bundle\Security\Serializer\ContextBuilder.inner' ]
        autoconfigure: false

    SuperAdmin\Bundle\EventListener\OwnedFilterConfigurator:
        tags:
            - { name: kernel.event_listener, event: kernel.request, priority: 5 }
        # Autoconfiguration must be disabled to set a custom priority
        autoconfigure: false
# File config/packages/doctrine.yaml

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'

        # IMPORTANT: You MUST configure your server version,
        # either here or in the DATABASE_URL env var (see .env file)
        #server_version: '5.7'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

        filters:
            owned_filter:
                class: SuperAdmin\Bundle\Filter\OwnedFilter

开发

Conventional Commits