liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony

Home Page:http://liip.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem passing Bearer Token to GET request

msechi opened this issue · comments

I am trying to test an api but I am having some issue passing the bearer token. I make a first call to get the token:

$client->request('POST', '/api/login_check', [], [],
    ['CONTENT_TYPE' => 'application/json'],
    json_encode(
        [
            "username" => $user->getUsername(),
            "password" => 'password',
        ]
    )
);

$response = $client->getResponse();
return json_decode($response->getContent())->token;

and a second one using the token:

$client->request('GET', '/api/my_endpoint', [], [], [
            'Authorization' => $token,
            'CONTENT_TYPE' => "application/json",
    ]);

$token is in the format "Bearer gfsjdlfglfdkgslkjfdlskjfljgk"

the message I get is {"code":401,"message":"JWT Token not found"}

if I change Authorization to HTTP_AUTHORIZATION I am getting status code 200 but the output is not the expected the endpoint should return and I can get using postman.

any help? what's the best way to pass a Bearer token to a GET request?

thanks
M

please ignore this. I just found out is a problem with api-platform, not really related to this bundle.