geoffry304 / yii2-authy
Yii2 authy 2FA
2.0.8
2018-11-30 11:52 UTC
Requires
- amnah/yii2-user: ^5.0
- authy/php: 3.0
- borales/yii2-phone-input: dev-master
- kartik-v/yii2-grid: @dev
- kartik-v/yii2-krajee-base: @dev
- mobiledetect/mobiledetectlib: ^2.8
README
扩展:使用Authy的2FA功能与Yii2和amnah/yii2-user
安装
安装 yii2-authy 的首选方法是使用 Composer。你可以在你的 composer.json
文件的 require 部分添加以下内容:
"geoffry304/yii2-authy": "*"
或者运行:
$ php composer.phar require geoffry304/yii2-authy "*"
你可以通过 下载ZIP格式的源码 来手动安装 yii2-authy。
运行迁移文件 php yii migrate --migrationPath=@vendor/geoffry304/yii2-authy/migrations
更新配置文件
// app/config/web.php return [ 'modules' => [ 'authy' => [ 'class' => 'geoffry304\authy\Module', 'api_key' => 'here your api key from authy', 'send_mail_from => 'demo@example.com' ], 'user' => [ 'class' => 'amnah\yii2\user\Module', 'modelClasses' => [ 'LoginForm' => 'geoffry304\authy\forms\LoginForm' ] ], ], ];
使用Authy
在尝试 performLogin 之前,你需要添加以下代码片段
$module2FA = Yii::$app->getModule('authy'); if ($module2FA) { Yii::$app->session->set('credentials', ['login' => $model->email, 'pwd' => $model->password, 'remember' => $rememberMe]); $returnUrl = $module2FA->validateLogin($model->getUser()); return $returnUrl; }
选项
模块 具有以下选项来修改其行为
- api_key:从Authy网站获取的密钥,用于与其建立连接。
- api_url:如果你想使用其他URL标准到 https://api.authy.com。
- default_expirytime:用户需要插入新令牌的过期时间,标准为30天。
- send_mail:当添加新设备时发送邮件,标准为true。
- send_mail_from:当send_mail开启时,发送邮件的发送者要求。
- logo:用于确认和注册表单以及发送邮件中的logo路径。
如果你需要额外的安全性,你可以在每个操作和控制器中检查当前会话是否仍然存在于数据库中。
更新配置文件
// app/config/web.php return [ 'bootstrap' => ['GlobalCheck'], 'components' => [ 'GlobalCheck'=> [ 'class'=>'geoffry304\authy\components\GlobalCheck' ], ], ];