定制 hiqdev/yii2-mfa 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hiqdev/yii2-mfa

Composer 安装命令:

composer require hiqdev/yii2-mfa

包简介

Multi-factor authentication for Yii2 projects

README 文档

README

Multi-factor authentication for Yii2 projects

Latest Stable Version Total Downloads Build Status Scrutinizer Code Coverage Scrutinizer Code Quality Dependency Status

This package provides:

  • TOTP - Time-based One-time Password Algorithm used for two factor authentication
  • checking for user allowed IPs
  • generation and checking recovery codes (PLANNED)

Uses:

Can be plugged into any exising Yii2 project. See how it is used in hiqdev/hiam.

Installation

The preferred way to install this yii2-extension is through composer.

Either run

php composer.phar require "hiqdev/yii2-mfa"

or add

"hiqdev/yii2-mfa": "*"

to the require section of your composer.json.

Configuration

This extension provides pluggable configuration to be used with composer-config-plugin.

Also you can use it usual way by copy-pasting config. See src/config/web.php for configuration example.

Available configuration parameters:

  • organization.name

For more details please see src/config/params.php.

Usage

This plugin provides behavior and configuration attaches it to user component on beforeLogin event. And then the behavior validates IPs and TOTP on every login.

To use this plugin you have to instantiate your \Yii->app->user->identity class from hiqdev\yii2\mfa\base\MfaIdentityInterface and implement all of the methods, which will return or set MFA properties. For example:

use hiqdev\yii2\mfa\base\MfaIdentityInterface;

class Identity implements MfaIdentityInterface
{
    ...

    /**
     * @inheritDoc
     */
    public function getUsername(): string
    {
        return $this->username;
    }

    /**
     * @inheritDoc
     */
    public function getTotpSecret(): string
    {
        return $this->totp_secret ?? '';
    }

    ...

IPs and TOTP functions are independent and you can provide just one of properties to have only corresponding functionality.

Usage with OAuth2

Also there is a configuration to provide MFA for OAuth2.

  • Require suggested "bshaffer/oauth2-server-php": '~1.7' package

  • Use hiqdev\yii2\mfa\GrantType\UserCredentials for configuring /oauth/token command via totp code. For example:

    'modules' => [ 'oauth2' => [ 'grantTypes' => [ 'user_credentials' => [ 'class' => \hiqdev\yii2\mfa\GrantType\UserCredentials::class, ], ], ], ]

  • Extend you Identity class from ApiMfaIdentityInterface.

  • Use actions:

    POST /mfa/totp/api-temporary-secret - Proviedes temporary secret to generate QR-code POST /mfa/totp/api-enable - Enables totp POST /mfa/totp/api-disable - Disables totp

Back redirection

For any MFA route, you can add a GET param ?back=https://some.site.com. It will redirect the user after a successful operation to the needed site. To avoid open redirect vulnerability, you need to validate the back param.

It should be done with \hiqdev\yii2\mfa\validator\BackUrlValidatorInterface which has a default implementation. You have to create your own and reinitialize it with the container definition:

config/web.php:

'container' => [
   'singletons' => [
       \hiqdev\yii2\mfa\validator\BackUrlValidatorInterface::class => \your\own\validator::class,
    ],
],

License

This project is released under the terms of the BSD-3-Clause license. Read more here.

Copyright © 2016-2018, HiQDev (http://hiqdev.com/)

统计信息

  • 总下载量: 15.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 6
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-10-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固