Check your bootstrap/app.php . Make sure you register your auth.basic , something like this:
$app->routeMiddleware([ 'auth.basic' => Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, ]);
After that, change your routes:
$app->get('/profile', ['middleware' => 'auth.basic', function() {
EDIT
If you want to use database instead of eloquent authentication, you can call:
Auth::setDefaultDriver('database');
Before attempting authentication:
Auth::attempt([ 'email' => ' info@foo.bar ', 'password' => 'secret', ]);
Edit No. 2
If you want AuthManager , you can define your own driver for the AuthManager class:
Auth::setDefaultDriver('basic'); Auth::extend('basic', function () { return new App\Auth\Basic(); });
And below is the App\Auth\Basic class of the App\Auth\Basic class:
<?php namespace App\Auth; use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Contracts\Auth\Authenticatable; class Basic implements UserProvider { public function retrieveById($identifier) { } public function retrieveByToken($identifier, $token) { } public function updateRememberToken(Authenticatable $user, $token) { } public function retrieveByCredentials(array $credentials) { return new User($credentials); } public function validateCredentials(Authenticatable $user, array $credentials) { $identifier = $user->getAuthIdentifier(); $password = $user->getAuthPassword(); return ($identifier === ' info@foobarinc.com ' && $password === 'password'); } }
Please note that the validateCredentials method of the first argument requires the implementation of the Illuminate\Contracts\Auth\Authenticatable interface, so you need to create your own User class:
<?php namespace App\Auth; use Illuminate\Support\Fluent; use Illuminate\Contracts\Auth\Authenticatable; class User extends Fluent implements Authenticatable { public function getAuthIdentifier() { return $this->email; } public function getAuthPassword() { return $this->password; } public function getRememberToken() { } public function setRememberToken($value) { } public function getRememberTokenName() { } }
And you can check your own driver using the Auth::attempt method:
Auth::setDefaultDriver('basic'); Auth::extend('basic', function () { return new App\Auth\Basic(); }); dd(Auth::attempt([ 'email' => ' info@foobarinc.com ', 'password' => 'password', ]));