我正在尝试将 JWT 添加到 .按照文档设置所有内容。https://jwt-auth.readthedocs.io/en/develop/quick-start/"tymon/jwt-auth": "^1.0"
Laravel Framework 7.26.1
这是我的AuthController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
class AuthController extends Controller
{
/**
* Create a new AuthController instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:api', ['except' => ['login']]);
}
/**
* Get a JWT via given credentials.
*
* @return \Illuminate\Http\JsonResponse
*/
public function login()
{
$credentials = request(['email', 'password']);
if (! $token = Auth::attempt($credentials)) {
return response()->json(['error' => 'Unauthorized'], 401);
}
return $this->respondWithToken($token);
}
...
这是 API.php
Route::post('login', 'AuthController@login')->middleware('api');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');
当试图从邮递员那里击中时,这就是我得到的http://127.0.0.1:8000/api/login/
海绵宝宝撒
心有法竹
梵蒂冈之花