colinlongworth's avatar

NTLM Authentication Library?

I'm working on a project requiring the employees to log in using their internal NTLM system. However, I can't find any up-to-date packages for Laravel, nor any guides (Except for some dated discussion relating to Laravel 5.x)

Is there an up-to-date package or guide on how to authenticate between Laravel and NTLM?

0 likes
2 replies
LaryAI's avatar
Level 58

One possible solution is to use the "php-ntlm" package, which provides a simple way to authenticate with NTLM in PHP. Here's how you can use it in Laravel:

  1. Install the package using Composer:
composer require php-ntlm/php-ntlm
  1. Create a new middleware class in your Laravel application. This middleware will handle the NTLM authentication process. You can generate the middleware using the following command:
php artisan make:middleware NtlmAuthMiddleware
  1. Open the generated NtlmAuthMiddleware class and update the handle method with the following code:
use Ntlm\Ntlm;

public function handle($request, Closure $next)
{
    $ntlm = new Ntlm();
    
    if (!$ntlm->isAuthenticated()) {
        return $ntlm->challenge();
    }
    
    return $next($request);
}
  1. Register the middleware in the app/Http/Kernel.php file. Add the following line to the $routeMiddleware array:
'ntlm' => \App\Http\Middleware\NtlmAuthMiddleware::class,
  1. Now you can apply the ntlm middleware to any routes or controllers that require NTLM authentication. For example, in your routes file:
Route::group(['middleware' => 'ntlm'], function () {
    // Routes that require NTLM authentication
});

This solution uses the "php-ntlm" package to handle the NTLM authentication process. The middleware checks if the user is authenticated using NTLM, and if not, it sends a challenge response to the client. If the user is authenticated, the middleware allows the request to proceed.

Note: This solution assumes that you have already configured your server to support NTLM authentication.

1 like
KristinGrady's avatar

@geometry dash subzero You can also build a custom middleware to handle NTLM authentication. This middleware will check the user's credentials and perform authentication via NTLM.

Please or to participate in this conversation.