我需要使用Laravel/Fortify以编程方式生成2FA密钥,但没有文档介绍如何做到这一点?
在我的User模型中,I am useing TwoFactorAuthenticable
class User extends Authenticatable
{
use TwoFactorAuthenticatable;并且在config/fortity.php中启用了TwoFactorAuthentication
'features' => [
Features::twoFactorAuthentication([
'confirmPassword' => true,
]),
],我尝试过像这样的函数:
// returns a "Call to undefined method" exception
$user->generateSecretKey();
// returns Decrypt error, presumably won't work without a secret set
$user->twoFactorQrCodeUrl();
$user->twoFactorQrCodeSvg();有没有人破解了怎么做?
发布于 2020-10-14 00:44:12
在深入研究之后,我发现vendors/laravel/fortify/src/Http/Controllers中的TwoFactorAuthenticationController实际上在store()函数中有一个示例
当我在我的UserObserver中使用它时,它是这样工作的:
use Laravel\Fortify\Actions\EnableTwoFactorAuthentication;
class UserObserver
{
public function created(User $user, EnableTwoFactorAuthentication $enable)
{
$enable($user);
...发布于 2021-07-27 19:13:11
从我的用户控制器...
use Laravel\Fortify\Actions\EnableTwoFactorAuthentication;
// Add Two Factor Authentication to this User
if ($request->tfa) {
$tfa = \App::make('Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider');
$enable = new EnableTwoFactorAuthentication($tfa);
$myrc = $enable($user);
}https://stackoverflow.com/questions/64339497
复制相似问题