CakePHP 4 Auth plugin API call

I am building an API and try to log in the users to he CakePHP backend. The users sends their email and password and they get a token and after that all API calls authenticated with the token.

I used the example codes from the cookbook.

When I send the credentials to the API’s /users/login.json url than $this->Authentication->getResult() status is FAILURE_OTHER with or without the correct credentials.

That is why forums are great tools… After a few hours of stuck with this problem I found the solution 2 minutes after posting the question :slight_smile:

$service->loadAuthenticator('Authentication.Form', [
  'fields' => $fields,
  'loginUrl' => '/users/login.json'

As the frontend app calls /users/login.json we have to have it as the loginUrl and not just /users/login.