vendredi 18 août 2017

Cannot override Laravel Spark authentication with own implementation

During the login process of Laravel Spark I need to request a token of a remote API. This API stores the exact same users and passwords as the Laravel Spark application. Therefore I need to get the username and non hashed password of the user during the authentication process.

I thought overriding the authenticated method would be the solution to my problem. In routes/web.php I override the POST /login endpoint and am pointing this endpoint to my own LoginController:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use Laravel\Spark\Http\Controllers\Auth\LoginController as SparkLoginController;

class LoginController extends SparkLoginController
{
    /**
     * Create a new login controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Handle a successful authentication attempt.
     *
     * @param  Request  $request
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @return Response
     */
    public function authenticated(Request $request, $user)
    {
        Log::info('authenticated method in LoginController has been called');

        return parent::authenticated($request, $user);
    }
}

This implementation throws a Missing argument 2 for App\Http\Controllers\Auth\LoginController::authenticated() exception. Somehow Laravel is not passing a User in the $user parameter. This exception is thrown whatever I do. Even removing the method out of my LoginController will result in the same exception thrown in the Spark LoginController.

When i disable my /login endpoint and log the $request and $user parameters of the authenticated method in the Spark LoginController, I see that $request contains Illuminate\Http\Request::__set_state(array(...)) and $user contains App\User::__set_state(array()). When I log the same in my own controller $request contains Illuminate\Http\Request::__set_state(array(...)) and $user is not passed.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wmC9m3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire