Your Location is: Home > Php

Consume API from backend not working with cookie on Symfony 5

From: Zambia View: 4992 Jiizen 

Question

I'm on Symfony 5 with API platform. In my application, the authentication is done by cookie ; not token.

I would call my URL from a service, but it doensn't work with the cookie in the headers. From the API interface, I can consume my resource. I can get the ressource by curl with --cookie, but in Insomnia, I don't understand why the call isn't working either...

In the documentation, it seems BrowserKit would make the job to fake the browser, but I want to be sure : I already used BrowserKit for testing and I thought it was ONLY for testing. It's the case or it's possible to use the BrowserKit for others things ?

The main question is : how to consume the API from backend on Symfony with a cookie (with HttpClient) ?

Best answer