I have successfully implemented authentication using ldap in Laravel 11.x with LdapRecord. However, I am unable to use Basic Authentication for api. Before using ldap, both web and api were using Basic Authentication. Now it returns 404 for api.
As an example, when sending a post request to http://192.168.56.101/api/user in api.php:
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth.basic');
I am using Insomnia with basic authentication set:
My setup as follows:
config/auth.php
'defaults' => [
'guard' => env('AUTH_GUARD', 'web'),
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'ldap',
],
'api' => [
'driver' => 'session',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => AppModelsUser::class,
],
'ldap' => [
'driver' => 'ldap',
'model' => AppLdapUser::class,
'rules' => [],
'scopes' => [],
'database' => [
'model' => AppModelsUser::class,
'sync_passwords' => false,
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
'user_id' => 'uid',
],
],
],
],
When I use the api, the following is logged:
Why does it seem to be using ldap?
Is it even possible to enable ldap for both web and basic for api?
I am keen on using Basic Authentication for API because it is simplest to use.
Worse to worse, I am also OK to use ldap for both web and api as an alternative