我将这些包与这些版本一起使用来为用户登录创建令牌,但在创建令牌时遇到此错误:
作曲家.json
"require": {
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.12",
"laravel/passport": "^10.1.3",
"laravel/tinker": "^2.5",
"laravel/ui": "^3.2",
"laravelcollective/html": "^6.2",
"lcobucci/jwt": "3.4.5",
"spatie/laravel-permission": "^4.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.9",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
}
路线/api.php
Route::post('login', [ApiLoginController::class, 'login']);
ApiLoginController.php
public function login(Request $request)
{
$this->validateLogin($request);
$user = User::where($this->username, $request->get('username'))
->first();
if (Auth::attempt([$this->username => $request->get('username'), 'password' => $request->get('password')])) {
if ($user->status != 'active') {
$msg = 'Account is not active';
return $this->customError($msg);
}
$success['token'] = $user->createToken('Personal Access Client')->accessToken;
$success['name'] = $user->name;
$success['phone'] = $user->phone;
$success['email'] = $user->email;
$user->password = null;
$user->save();
return $this->success($success, "Login completed successfully");
}
//delete user password
if ($user){
$user->password = null;
$user->save();
}
$msg = 'The information entered does not match our information';
return $this->customError($msg);
}
邮递员回应
{
"message": "Method Laravel\\Passport\\Bridge\\AccessToken::__toString() must not throw an exception, caught Lcobucci\\JWT\\Signer\\InvalidKeyProvided: It was not possible to parse your key, reason: error:0908F070:PEM routines:get_header_and_data:short header",
"exception": "Symfony\\Component\\ErrorHandler\\Error\\FatalError",
"file": "F:\\xampp\\htdocs\\Diapad-BackEnd\\vendor\\league\\oauth2-server\\src\\ResponseTypes\\BearerTokenResponse.php",
"line": 0,
"trace": []
}
此过程无需令牌线即可工作。甚至创建了一个标记但不作为字符串返回。我多次降低甚至升级了我的软件包版本,但它没有工作。