James mcconnon James mcconnon - 1 year ago 176
reST (reStructuredText) Question

401 unauthorised using a bearer token with Laravel Passport

So, I have created a site using Laravel 5.3 and I have installed passport.

As far as I can see everything is working just fine with the install and the Vue components to create a token etc.

I have created a personal token in my user area and attempted to use that to authorise with the API but I am getting 401 unauthorised every time.

My headers with the request in postman Postman header settings

Am i missing something with the settings here?

I have also tried following the oauth flow in a seperate "consumer.dev" and im getting unauthorised errors there aswell.

I have checked the contents of my config/auth.php and that has the correct driver declaration.

'api' => [
'driver' => 'passport',
'provider' => 'users',

I am a touch confused where to go from here. Any help is appreciated.

Answer Source

Ok so thanks a ton jemaclus from laravel.io chat for this fix.

I will search again to find the page, but he directed me to a page that showed that if you use apache with the JWT token package used in passport, it strips the Authorization header out of the request without some modification to the virtual host in apache.

As a result i switched back to nginx (moved back to using homestead) and all requests in the same project worked perfectly!

In my case i was using Laragon as a test environment (ships with apache on-board, and not nginx)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download