每当我需要帮助时,我都会在stackoverflow中找到所有问题,但是我仍然找不到解决方案。
我将laravel 6和护照8用于oauth,我将在http://localhost/oauth/token上访问令牌
我使用客户密码 我认为这就是问题所在,但我不确定。
我的注册码
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
'username' => 'required',
'email' => 'required|email',
'password' => 'required',
'confirm_password' => 'required|same:password',
]);
if ($validator->fails()) {
return response()->json(['error'=>$validator->errors()], 401);
}
$input = $request->all();
$input['password'] = Hash::make($input['username'].$input['password']);
$user = User::create($input);
$success['token'] = $user->createToken('MyApp')-> accessToken;
$success['name'] = $user->name;
return response()->json(['success'=>$success], $this-> successStatus);
}
我尝试了stackoverflow之类的功能
这是我的模型/用户
private $user_password;
/**
* Find the user instance for the given username.
*
* @param string $username
* @return \App\Model\User
*/
public function findForPassport($username)
{
$user = $this->where('username', $username)->first();
$this->user_password = $user->username.$user->password;
return $user;
}
/**
* Validate the password of the user for the Passport password grant.
*
* @param string $password
* @return bool
*/
public function validateForPassportPasswordGrant($password)
{
return Hash::check($this->user_password, $this->password);
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->user_password;
}
此文件config / auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => true,
],
],