在 laravel/fortify 中使用 api 令牌进行身份验证

Authentication using api token in laravel/fortify

我正在使用 laravel/fortify 并且我正在尝试使用 HTTP 客户端请求进行身份验证

public function boot()
{
    Fortify::loginView(function () {
        return view('auth.login');
    });
    Fortify::authenticateUsing(function (Request $request) {
        $response = Http::withHeaders([
            'content-type' => 'application/json',
            'Accept' =>'application/json',
        ])->post('http://127.0.0.1:8001/v1/login', [
            'email' => $request->email,
            'password' => $request->password
        ]);
        if($response->ok()) {
            //Session::put('token',$response['access_token']);
            $data = $response->json();
            return $data;
        }

});

但我收到错误消息,错误是:

TypeError
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of 
Illuminate\Contracts\Auth\Authenticatable, array given, called in 
home/suraj/Documents/locaxapp/client/locux/source/clients/vendor/laravel/fortify/src/
Actions/AttemptToAuthenticate.php on line 77

return 这样的用户实例

 Fortify::authenticateUsing(function (Request $request) {
            $response = Http::withHeaders([
                'content-type' => 'application/json',
                'Accept' =>'application/json',
            ])->post('http://127.0.0.1:8001/v1/login', [
                'email' => $request->email,
                'password' => $request->password
            ]);
            if($response->ok()) {
                //Session::put('token',$response['access_token']);
                $data = $response->json();
                return User::find($data->id);
            }

或者你如官方文档所述

Fortify::authenticateUsing(function (Request $request) {
    $user = User::where('email', $request->email)->first();

    if ($user &&
        Hash::check($request->password, $user->password)) {
        return $user;
    }
})

ref link https://jetstream.laravel.com/1.x/features/authentication.html