laravellaravel-5basic-authenticationlaravel-middleware

Laravel 5 - how to use basic auth with username in place of email?


Hello guys !

So in Laravel 4 we could do

Route::filter('auth.basic', function()
{
    return Auth::basic('username');
});

But now it's not possible, and the doc doesn't give a clue about how to. So can anyone help ?

Thanks !


Solution

  • Create a new custom middleware using the same code as the default one:

    https://github.com/laravel/framework/blob/5.0/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php

    and override the default 'email' field like:

    return $this->auth->basic('username') ?: $next($request);