#Cannot use Laravel nova Api, get 401 with authorized key

1 messages · Page 1 of 1 (latest)

eternal aspen
#

I successfull test sanctum with my jetstream personal access token.

I can't use the nova-api, because I get an unauthorized

public function test_main_resources(): void
{
    $response = $this->withHeaders([
    'Authorization' => env('API_TOKEN'),
    ])->get(env('APP_URL') . '/nova-api/search');
    $response->assertStatus(200);
}

APP_URL=http://127.0.0.1:8000
Token is authorized and stands in peronsal access tokens table

lean belfry
#

Think you'll need to use Bearer: TOKEN

eternal aspen
#

'Authorization' => 'Bearer ' . env('API_TOKEN'),

#

'Authorization' => 'Bearer ' . 'N2A2lyi7UymDtxy4iv5wQkbiMpQ1j7sDEg6ccpOfZsvlqfV6eI',
//401

lean belfry
#

Then it's probably because you're running your tests on a different database (or you're using the refresh thing). So a better way would be to create a user and a token in your test and use that, instead of env values (using env values is kinda bad anyways)

eternal aspen
#

Okay
So it's better to test it in Postman

#

Is the Authorisation in Postman with API Token?