E1.31 Php Symfony Security Step 12: Modify security.yaml (Wpf, Xamarin, Angular SPA, Reactjs SPA) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

Open any Security Controller for Doctrine setting

  • Open the "AspnetuserViewKeyAuthenticator.php"-file

picture

At the begining of the file you wil find the following instructions

...
// ///////////////////////////////////////////////////////////////////////////////
// Important note:
// the generated code expects "config/packages/security.yaml"-file to have the following config parameters
// ///////////////////////////////////////////////////////////////////////////////
//
//security:
//    # https://symfony.com/doc/current/security/authenticator_manager.html
//    enable_authenticator_manager: true
//    # https://symfony.com/doc/current/security.html#c-hashing-passwords
//    password_hashers:
//        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
//        App\Entity\AspnetuserViewEntityUpd:
//            algorithm: auto
//
//    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
//    providers:
//        # used to reload user from session & other features (e.g. switch_user)
//        app_user_provider:
//            entity:
//                class: App\Entity\AspnetuserViewEntityUpd
//                property: username
//    firewalls:
//        main:
//            custom_authenticators:
//                - App\Security +"\\"+ AspnetuserViewKeyAuthenticator
//                               
//            # activate different ways to authenticate
//            # https://symfony.com/doc/current/security.html#firewalls-authentication
//
//            # https://symfony.com/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: ^/token, roles: PUBLIC_ACCESS }
//        - { path: ^/api/Account/ChangePassword, roles: IS_AUTHENTICATED_FULLY }
//        - { path: ^/api/Account/Logout, roles: IS_AUTHENTICATED_FULLY }
//
// ///////////////////////////////////////////////////////////////////////////////

  • modify "config/packages/security.yaml"-file according to the instructions:
security:
    # https://symfony.com/doc/current/security/authenticator_manager.html
    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#c-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
        App\Entity\AspnetuserViewEntityUpd:
            algorithm: auto

    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            entity:
                class: App\Entity\AspnetuserViewEntityUpd
                property: username
    firewalls:
        main:
            custom_authenticators:
                - App\Security\AspnetuserViewKeyAuthenticator
                               
            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#firewalls-authentication

            # https://symfony.com/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: ^/token, roles: PUBLIC_ACCESS }
        - { path: ^/api/Account/ChangePassword, roles: IS_AUTHENTICATED_FULLY }
        - { path: ^/api/Account/Logout, roles: IS_AUTHENTICATED_FULLY }

Note

  • AspnetuserViewAuthController.php declares the rotes:
    • /api/Account/ChangePassword (IS_AUTHENTICATED_FULLY)
    • /token (PUBLIC_ACCESS)
    • /api/Account/Logout (IS_AUTHENTICATED_FULLY)
    • /api/Account/Register (PUBLIC_ACCESS)