Multiple Auth Guards?
- Dominant language
- PHP
- Stars
- 9.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | no
| Framework | Laravel
| Framework version | 5.5
| PHP version | 7.1.11
#### Actual Behaviour
Hello everyone... I'm having the following problem.. I use web guard with "Collaborator" model, but in api guard, I want to use "Responsible" model for authentication (basic)...
When I set an username/password of "Collaborator" in Authentication header, the request return success. But when I set an username/password of "Responsible" model it returns "Invalid credentials".
Can anyone help-me with this problem? Here's some pieces of code:
config/auth.php
```
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'Collaborator',
],
'api' => [
'driver' => 'token',
'provider' => 'Responsible',
],
],
'providers' => [
'Collaborator' => [
'driver' => 'eloquent',
'model' => App\Models\Collaborator::class,
],
'Responsible' => [
'driver' => 'eloquent',
'model' => App\Models\Responsible::class,
],
]
```
App/Providers/ApiServiceProvider.php
```
public function register()
{
$this->app['Dingo\Api\Transformer\Factory']->setAdapter(function ($app) {
$fractal = new Manager();
$fractal->setSerializer(new JsonApiSerializer());
return new Fractal($fractal);
});
app('Dingo\Api\Auth\Auth')->extend('basic', function ($app) {
return new Basic($app['auth'], 'cpf');
});
}
```
routes/api.php
```
$api->version('v1', function ($api) {
$api->group(['namespace' => 'App\Api\V1\Controllers'], function ($api) { // Use this route group for v1
$api->post('/login', 'AuthController@login')->name('users.login');
$api->get('/teste', 'AuthController@teste')->name('users.test')->middleware('api.auth');
});
});
```
Contributor guide
Assessment
This issue has not been assessed yet.