Используйте HWIOAUTHBundle с LexikJWT в проекте API-платформы.

У меня нет проблем с созданием API с помощью API-платформы, созданием токена с помощью LexikJwt и обновлением с помощью комплекта gedinet. Это легко (большое спасибо, это отличный документ).

Я использую Symfony 6.1 и пытаюсь интегрировать HWIOAUTH Bundle 2.0 (бета).

Мой вариант использования: используйте Azure (Office 365) для аутентификации пользователя в моем API.

В настоящее время я настроил 2 провайдера (Entity и Memory). И я хотел бы использовать третий: Azure

Моя безопасность.yml

      security:
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
    # https://symfony.com/doc/current/security/authenticator_manager.html
    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    role_hierarchy:
        ROLE_EMPLOYEE:      ROLE_USER
        ROLE_COMPANY:       ROLE_USER
        ROLE_ADMIN:         [ROLE_EMPLOYEE, ROLE_COMPANY]
        ROLE_SUPPORT:       [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
        ROLE_SUPER_ADMIN:   [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
        support_provider:
            memory:
                users:
                    super_admin: { password: 'aPasswordhash', roles: ['ROLE_SUPER_ADMIN'] } 
                    support: { password: 'aPasswordhash', roles: ['ROLE_SUPPORT'] }
        chain_provider:
            chain:
                providers: ['app_user_provider', 'support_provider']
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            stateless: true
            provider: chain_provider
            entry_point: jwt
            json_login:
                check_path: /login_check
                username_path: email
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
            # https://symfony.com/doc/current/security/impersonating_user.html
            switch_user: true
            jwt: ~
            refresh_jwt:
                check_path: /refresh
            logout:
                path: logout
            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#the-firewall

    # 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: PUBLIC_ACCESS }
        - { path: ^/refresh,        roles: PUBLIC_ACCESS }
        - { path: ^/login_check,    roles: PUBLIC_ACCESS }
        # - { path: ^/logout,       roles: IS_AUTHENTICATED_FULLY }
        # - { path: ^/admin, roles: ROLE_ADMIN }
        # - { path: ^/profile, roles: ROLE_USER }

when@test:
    security:
        password_hashers:
            # By default, password hashers are resource intensive and take time. This is
            # important to generate secure password hashes. In tests however, secure hashes
            # are not important, waste resources and increase test times. The following
            # reduces the work factor to the lowest possible values.
            Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
                algorithm: auto
                cost: 4 # Lowest possible value for bcrypt
                time_cost: 3 # Lowest possible value for argon
                memory_cost: 10 # Lowest possible value for argon

Остальная часть моей конфигурации соответствует пакетному документу.

Я понятия не имею, как заставить их (эти 3 провайдера) работать под одним и тем же логином и сохранить пользователя Azure (office365) в моей базе данных! Это моя проблема.

Есть ли у вас какие-либо идеи?

Я попытался дополнить свой chain_provider сервисом hwi_oauth. Я думал использовать другой способ (SAML) или второй маршрут для входа в систему, но мы потеряли использование безопасности JWT.

0 ответов

Другие вопросы по тегам