dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.33k stars 1.25k forks source link

Help me please with basic auth #1634

Open deepslam opened 5 years ago

deepslam commented 5 years ago

Hi everyone!

I'm sorry for this popular question but I can't configure basic auth for my API. I've putted this code into by AppServiceProvider:

app('Dingo\Api\Auth\Auth')->extend('basic', function ($app) {
   return new Dingo\Api\Auth\Provider\Basic($app['auth'], 'email');
});

But I got 401 message that client couldn't be authorized. At the same time, I'm authorized in my admin panel via cookie and laravel session. I also send X-CSRF-TOKEN in my headers but I still get 401 error.

Help me, please. I think I have a misunderstanding with some basic knowledge.

Sincerely, Dmitry

specialtactics commented 5 years ago

We've had a lot of trouble with that approach, so the better approach I would recommend is just to use your own custom basic auth middleware. Fortunately basic auth is incredibly easy to implement, so just create a new middleware in your App\ and any route you want to have it, add it as the middlware (making sure not to mix and match with api.auth middleware).