Laravel 护照自定义哈希机制
Laravel Passport Custom Hashing Mechanism
我目前正在构建一个与更大的应用程序 (Zend 1.x) 一起工作的应用程序(使用 Laravel)。
我正在使用 Laravel 护照进行 API 身份验证。我需要将 Laravel Passport 默认散列机制更改为 Zend 散列,以便进行身份验证。
有人可以指出 API 或我需要重写才能获得此 运行 的内容吗?我宁愿不编辑核心 Laravel 护照代码。
我看到了创建自定义用户提供程序和修改 validateCredentials()
方法的建议,但这些都是针对核心 Laravel 的。
我已经在用户 class 中使用 findForPassport 方法来覆盖用户名字段。
public function findForPassport($username)
{
return $this->where('email', $username)->first();
}
对于任何想知道的人,您可以覆盖用户 class 中的 2 个方法(可能更多)来处理自定义 Laravel 护照身份验证:
/**
* Override the field which is used for username in the authentication
*/
public function findForPassport($username)
{
return $this->where('email', $username)->first();
}
/**
* Add a password validation callback
*
* @param type $password
* @return boolean Whether the password is valid
*/
public function validateForPassportPasswordGrant($password)
{
$hasher = new HSAUserHasher(); // Or whomever does your hashing
$result = $hasher->create_hash($password, $this->salt);
$hashedPassword = $result['password'];
return $hashedPassword == $this->password;
}
感谢 Laravel slack 论坛 (https://larachat.slack.com) 上的@redviking 帮助我找到答案。
我目前正在构建一个与更大的应用程序 (Zend 1.x) 一起工作的应用程序(使用 Laravel)。
我正在使用 Laravel 护照进行 API 身份验证。我需要将 Laravel Passport 默认散列机制更改为 Zend 散列,以便进行身份验证。
有人可以指出 API 或我需要重写才能获得此 运行 的内容吗?我宁愿不编辑核心 Laravel 护照代码。
我看到了创建自定义用户提供程序和修改 validateCredentials()
方法的建议,但这些都是针对核心 Laravel 的。
我已经在用户 class 中使用 findForPassport 方法来覆盖用户名字段。
public function findForPassport($username)
{
return $this->where('email', $username)->first();
}
对于任何想知道的人,您可以覆盖用户 class 中的 2 个方法(可能更多)来处理自定义 Laravel 护照身份验证:
/**
* Override the field which is used for username in the authentication
*/
public function findForPassport($username)
{
return $this->where('email', $username)->first();
}
/**
* Add a password validation callback
*
* @param type $password
* @return boolean Whether the password is valid
*/
public function validateForPassportPasswordGrant($password)
{
$hasher = new HSAUserHasher(); // Or whomever does your hashing
$result = $hasher->create_hash($password, $this->salt);
$hashedPassword = $result['password'];
return $hashedPassword == $this->password;
}
感谢 Laravel slack 论坛 (https://larachat.slack.com) 上的@redviking 帮助我找到答案。