Get AD user after login #435
-
I need to filter information on the controller based on the OU of the user logged in via AD and I cannot find a way to access such information. <?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements LdapAuthenticatable
{
use AuthenticatesWithLdap;
use HasRoles;
use Notifiable;
protected string $guard_name = 'web';
} My AuthServiceProvider: <?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Auth;
use Laravel\Fortify\Fortify;
class AuthServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->registerPolicies();
Fortify::authenticateUsing(static function ($request) {
Auth::attempt([
'sAMAccountName' => $request->username,
'password' => $request->password,
]);
return Auth::user();
});
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @lucraraujo, Can you clarify what you mean by "filter information on the controller"? Do you mean restrict access by redirecting the user with middleware? Or limiting what users can see inside of a blade view? Etc. Give me an example of what you'd like to achieve, and I can help you get there 👍 |
Beta Was this translation helpful? Give feedback.
Hi @lucraraujo,
Can you clarify what you mean by "filter information on the controller"?
Do you mean restrict access by redirecting the user with middleware? Or limiting what users can see inside of a blade view? Etc.
Give me an example of what you'd like to achieve, and I can help you get there 👍