[英]How to login with url and hash parameter only in Laravel? (without username and password)
[英]Laravel Passport: login using only username without password
在我的项目中,我将通过发送带有短信的确认码来验证用户电话号码。 确认后,我必须向我的laravel应用程序发送登录请求。 在Laravel Passport文档中有登录用户的示例请求:
$response = $http->post('http://your-app.com/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => 'client-id',
'client_secret' => 'client-secret',
'username' => 'taylor@laravel.com',
'password' => 'my-password',
'scope' => '',
],
]);
我如何设置username
用户phone
并删除password
?
如果Laravel Passport中需要password
字段,那么从客户端我可以在attempt
用户凭据之前发送任何密码和owerride请求用户password
。 但在哪里我必须提供密码?
我已经厌倦了改变LoginController
但没有工作。
的LoginController
protected function validateLogin(Request $request)
{
$request->validate([
$this->username() => 'required|string'
]);
}
protected function credentials(Request $request)
{
$params = [
'password' => '12345678',
];
$request->request->add($params);
return $request->only($this->username(), 'password');
}
public function username()
{
return 'phone';
}
用户模型中的usefindForPassport方法。
它将用户名作为参数,并返回用户模型
已在这里回答
class User extends Authenticatable
{
use Notifiable, HasApiTokens;
// Set as username any column from users table
public function findForPassport($username)
{
$customUsername = 'phone';
return $this->where($customUsername, $username)->first();
}
// Owerride password here
public function validateForPassportPasswordGrant($password)
{
$owerridedPassword = 'password';
return Hash::check($password, $this->password);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.