I am having difficulty authenticating through the Json Web Token token (JWT) in the Laravel framework, I have been using the framework recently and have come across the following error.
Whoops, looks like something went wrong.
1/1
ErrorException in EloquentUserProvider.php line 112:
Undefined index: password
in EloquentUserProvider.php line 112
at HandleExceptions->handleError('8', 'Undefined index: password', 'D:\web\XAMPP\htdocs\SIAPE\vendor\laravel\framework\src\Illuminate\Auth\EloquentUserProvider.php', '112', array('user' => object(User), 'credentials' => array('A901_codusu' => '1', 'A901_login' => 'MASTER'))) in EloquentUserProvider.php line 112
at EloquentUserProvider->validateCredentials(object(User), array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in Guard.php line 390
at Guard->hasValidCredentials(object(User), array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in Guard.php line 370
at Guard->attempt(array('A901_codusu' => '1', 'A901_login' => 'MASTER'), false, false) in Guard.php line 275
at Guard->validate(array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in Guard.php line 258
at Guard->once(array('A901_codusu' => '1', 'A901_login' => 'MASTER'))
at call_user_func_array(array(object(Guard), 'once'), array(array('A901_codusu' => '1', 'A901_login' => 'MASTER'))) in Manager.php line 137
at Manager->__call('once', array(array('A901_codusu' => '1', 'A901_login' => 'MASTER'))) in IlluminateAuthAdapter.php line 31
at AuthManager->once(array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in IlluminateAuthAdapter.php line 31
at IlluminateAuthAdapter->byCredentials(array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in JWTAuth.php line 99
at JWTAuth->attempt(array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in Facade.php line 216
at Facade::__callStatic('attempt', array(array('A901_codusu' => '1', 'A901_login' => 'MASTER'))) in AuthenticateController.php line 29
at JWTAuth::attempt(array('A901_codusu' => '1', 'A901_login' => 'MASTER')) in AuthenticateController.php line 29
at AuthenticateController->authenticate(object(Request))
at call_user_func_array(array(object(AuthenticateController), 'authenticate'), array(object(Request))) in Controller.php line 256
at Controller->callAction('authenticate', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthenticateController), object(Route), 'authenticate') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(AuthenticateController), object(Route), object(Request), 'authenticate') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'SIAPE\Http\Controllers\AuthenticateController', 'authenticate') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 712
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 714
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 679
at Router->dispatchToRoute(object(Request)) in Router.php line 639
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
at require_once('D:\web\XAMPP\htdocs\SIAPE\public\index.php') in index.php line 21
Here I was following this Tutorial tutorial, steps, except those referring to the user table, which uses the framework of the framework itself. I have my own user table, so I have no interest in using laravel. This error appears to me because I do not have a password field in my database, I have already changed the app.php, jwt.php files regarding the User table but it seems that the framework requires that my table has a field with this name "password" for authentication. my controler looks like this:
<?php
class AuthenticateController extends Controller
{
public function index()
{
// TODO: show users
}
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = $request->only('A901_codusu', 'A901_login');
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
public function getAuthenticatedUser()
{
try {
if (! $user = JWTAuth::parseToken()->authenticate()) {
return response()->json(['user_not_found'], 404);
}
} catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
return response()->json(['token_expired'], $e->getStatusCode());
} catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
return response()->json(['token_invalid'], $e->getStatusCode());
} catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
return response()->json(['token_absent'], $e->getStatusCode());
}
// the token is valid and we have found the user via the sub claim
return response()->json(compact('user'));
}
}
I need to find a way for Laravel to recognize my table ("T901_Usuarios") and not require that I have a "password" field to authenticate.