Home > Net >  How json authentication works with symfony?
How json authentication works with symfony?

Time:05-24

I can’t figure out what’s blocking. I’ve been following the symfony documentation.

/security.yaml

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.html#loading-the-user-the-user-provider
providers:
    # users_in_memory: { memory: null }
    app_user_provider:
        entity:
            class: App\Entity\User
            property: email
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        #lazy: true
        provider: app_user_provider
        json_login:
            # api_login is a route we will create below
            check_path: api_login
            #username_path: email
            #password_path: password
            #username_path: security.credentials.email
            #password_path: security.credentials.password

/controller/ApiLoginController.php

#[Route('/login', name: 'app_api_login', methods: 'POST')]
public function index(#[CurrentUser] ?User $user): Response
{
    dd($user);
}

i set the Content-Type application/json in header's request and i put in the body the json {"username": "[email protected]","password": "root"} and i post that request with postman.

I get always null as response... your help is welcome

CodePudding user response:

Ok i change

check_path: api_login

by

check_path: app_api_login

check_path must bee same as name: 'app_api_login' omg ....

  • Related