定制 godzillante/u2f-two-factor-bundle 二次开发

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

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

godzillante/u2f-two-factor-bundle

Composer 安装命令:

composer require godzillante/u2f-two-factor-bundle

包简介

Use U2F-Keys as 2FA for Symfony, using scheb/two-factor-bundle

README 文档

README

This Symfony2 bundle provides u2f authentication for your website using scheb/two-factor-bundle.

Installation

Step 1: Download using Composer

php composer.phar require tubssz/u2f-two-factor-bundle

Step 2: Enable the bundles

Add this to you app/AppKernel.php:

<?php

// ...
public function registerBundles()
{
    $bundles = array(
        // ...
        new Scheb\TwoFactorBundle\SchebTwoFactorBundle(),
        new R\U2FTwoFactorBundle\RU2FTwoFactorBundle(),
        // ...
    );
    // ...
}
// ...

Step 3: Configure

These options are available but not required:

r_u2f_two_factor:
    formTemplate: RU2FTwoFActorBundle:Authentication:form.html.twig
    registerTemplate: RU2FTwoFActorBundle:Registration:register.html.twig
    authCodeParameter: _auth_code

For the Authentication to work you User has to implement R\U2FTwoFactorBundle\Model\U2F\TwoFactorInterface

<?php

// ...
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorInterface as U2FTwoFactorInterface;
// ...
class User implements U2FTwoFactorInterface
{
// ...
    /**
     * @ORM\OneToMany(targetEntity="Club\BaseBundle\Entity\U2FKey", mappedBy="user")
     * @var ArrayCollection
     **/
    protected $u2fKeys;

    /**
     * isU2FAuthEnabled
     * @return boolean
     **/
    public function isU2FAuthEnabled()
    {
        // If the User has Keys associated, use U2F
        // You may use a different logic here
        return count($this->u2fKeys) > 0;
    }

    /**
     * getU2FKeys
     * @return ArrayCollection
     **/
    public function getU2FKeys()
    {
        return $this->u2fKeys;
    }

    /**
     * addU2FKey
     * @param U2FKey $key
     * @return void
     **/
    public function addU2FKey($key)
    {
        $this->u2fKeys->add($key);
    }

    /**
     * __construct
     * @return void
     **/
    public function __construct()
    {
        // ...
        $this->u2fKeys = new ArrayCollection();
        // ...
    }
}

For the Registration you also need an entity that implements R\U2FTwoFactorBundle\Model\U2F\TwoFactorKeyInterface. Here is an example using doctrine.

<?php
// ...
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorKeyInterface;

/**
 * Class U2FKey
 * @ORM\Entity
 * @ORM\Table(name="u2f_keys",
 * uniqueConstraints={@ORM\UniqueConstraint(name="user_unique",columns={"user_id",
 * "key_handle"})})
 */
class U2FKey implements TwoFactorKeyInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     * @var string
     **/
    public $keyHandle;

    /**
     * @ORM\Column(type="string")
     * @var string
     **/
    public $publicKey;

    /**
     * @ORM\Column(type="string")
     * @var string
     **/
    public $certificate;

    /**
     * @ORM\Column(type="string")
     * @var int
     **/
    public $counter;

    /**
     * @ORM\ManyToOne(targetEntity="AcmeBundle\Entity\User", inversedBy="u2fKeys")
     * @var User
     **/
    protected $user;

    /**
     * @ORM\Column(type="string")
     * @var string
     **/
    protected $name;

// ...
}

Then you need to create an eventlistener to get and store the data of the registered key.

<?php

use AcmeBundle\Entity\U2FKey;
use R\U2FTwoFactorBundle\Event\RegisterEvent;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class U2FRegistrationListener implements EventSubscriberInterface
{
    // ..
    /**
     * getSubscribedEvents
     * @return array
     **/
    public static function getSubscribedEvents()
    {
        return array(
            'r_u2f_two_factor.register' => 'onRegister',
        );
    }

    /**
     * onRegister
     * @param RegisterEvent $event
     * @return void
     **/
    public function onRegister(RegisterEvent $event)
    {
        $user = $event->getUser($event);
        $registrationData = $event->getRegistration();
        $newKey = new U2FKey();
        $newKey->fromRegistrationData($registrationData);
        $newKey->setUser($user);
        $newKey->setName($event->getKeyName());

        // persist the new key

        // generate new response, here we redirect the user to the fos user
        // profile
        $response = new RedirectResponse($this->router->generate('fos_user_profile_show'));
        $event->setResponse($response);
    }
}

Add it to your services.yml:

acme.u2f_listener:
    class: AcmeBundle\EventListener\U2FRegistrationListener
    tags:
        - { name: kernel.event_subscriber }

Also add routing definitions to your app/config/routing.yml

r_u2f:
    resource: "@RU2FTwoFactorBundle/Resources/config/routing.yml"
    prefix: /

The Keys can be registered visiting /u2f_register. It needs to be served as https!

License

This bundle is available under the MIT license.

godzillante/u2f-two-factor-bundle 适用场景与选型建议

godzillante/u2f-two-factor-bundle 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「Authentication」 「two-factor」 「yubikey」 「two-step」 「fido」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 godzillante/u2f-two-factor-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 godzillante/u2f-two-factor-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 godzillante/u2f-two-factor-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 9
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-08