定制 finpin/sezame-sdk 二次开发

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

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

finpin/sezame-sdk

Composer 安装命令:

composer require finpin/sezame-sdk

包简介

Passwordless multi-factor authentication

README 文档

README

Latest Stable Version Total Downloads License

Passwordless multi-factor authentication.

Unlike password-based solutions that require you to remember just another PIN or password, sezame is a secure and simple multi-factor authentication solution. You only need the username and your fingerprint on your smartphone to log into any sezame-enabled site. Magic – Sezame – ENTER SIMPLICITY!.

Installation

Use Composer to install the library.

$ composer require finpin/sezame-sdk

Steps

To be able to use Sezame within your application you have to fullfill these steps:

  1. download and install the Sezame app from an app store
  2. follow the registration process in the app
  3. register your application/client
  4. obtain a SSL client certificate
  5. let your users pair their devices with your application
  6. issue authentication requests

If you don not have a supported device with fingerprint reader, you must obtain the ssl certificate by using the support channels of Sezame.

Usage

register

To be able to connect to the Sezame HQ server, you have to register your client/application, this is done by sending the register call using your recovery e-mail entered during the app installation process. You'll get an authentication request on your Sezame app, which must be authorized.

$client = new \SezameLib\Client();

$registerRequest = $client->register()->setEmail('example@example.com')->setName('my new client');

$registerResponse = $registerRequest->send();

$clientcode   = $registerResponse->getClientCode();
$sharedsecret = $registerResponse->getSharedSecret();

sign

After you have authorized the registration on your mobile device you can request the certificate.

$client = new \SezameLib\Client();

$privateKeyPassword = 'somethingsecret';

$csrKey = $client->makeCsr($clientcode, 'example@example.com', $privateKeyPassword,
  Array(
    'countryName'            => 'AT',
    'stateOrProvinceName'    => 'Vienna',
    'localityName'           => 'Vienna',
    'organizationName'       => 'my company name',
    'organizationalUnitName' => 'IT division'
  ));

$signRequest = $client->sign()->setCSR($csrKey->csr)->setSharedSecret($sharedsecret);

$signResponse = $signRequest->send();

$cert = $signResponse->getCertificate();

printf("CSR:\n%s\n\n", $csrKey->csr);
printf("Certificate:\n%s\n\n", $cert);
printf("Private Key:\n%s\n\n", $csrKey->key);

Store the certificate and the private key within your system, it is recommended to protect your private key with a secure passphrase. The certificate and the private key is needed for subsequent calls to the Sezame servers, sign and register are the only two calls which can be used without the client certificate.

pair

Once you have successfully obtained the client certificate, let your customers pair their devices with your application, this is done by displaying a QR code which is read by the Sezame app.

use Endroid\QrCode\Writer;

$client = new \SezameLib\Client($certfile, $keyfile);

$username = 'foo-client-user';

// check pairing status of a certain user
$statusRequest = $client->linkStatus();
$statusResponse = $statusRequest->setUsername($username)->send();

if ($statusResponse->isLinked()) {
  print "user already has been linked\n";
  die;
}

$linkRequest = $client->link();
$linkResponse = $linkRequest->setUsername($username)->send();

if ($linkResponse->isDuplicate()) {
  print "user already has been linked\n";
  die;
}

$qrCode = $linkResponse->getQrCode($username);
$qrCode->setSize(300)->setLabelMargin([
        't' => 10,
        'r' => 10,
        'b' => 10,
        'l' => 10,
]); // optionally adjust qrcode dimensions

printf('<img src="%s"/>', $qrCode->writeString(Writer\PngDataUriWriter::class));

file_put_contents('qrcode.html', sprintf('<img src="%s"/>', $qrCode->writeString(Writer\PngDataUriWriter::class)));

auth

To authenticate users with Sezame, use the auth call.

$client = new \SezameLib\Client($certfile, $keyfile, $keyPassword);
$username = 'foo-client-user';

$timeout = 10;
$authRequest = $client->authorize();
$authRequest->setUsername($username);
$authResponse = $authRequest->send();

if ($authResponse->isNotfound()) {
  // user not paired
}

if ($authResponse->isOk())
{
  $statusRequest = $client->status();
  $statusRequest->setAuthId($authResponse->getId());
  for ($i = 0; $i < $timeout; $i++)
  {
    $statusResponse = $statusRequest->send();
    if ($statusResponse->isAuthorized())
    {
      // request has been authorized
    }
    if ($statusResponse->isDenied()) 
    {
      // request has been denied
    }
    
    sleep(1);
  }
  
  printf("user did not respond within %d seconds\n", $timeout);
}

fraud

It is possible to inform users about fraud attempts, this request could be send, if the user logs in using the password.

$client = new \SezameLib\Client($certfile, $keyfile, $keyPassword);
$username = 'foo-client-user';
$authRequest = $client->authorize();
$authRequest->setType('fraud');
$authRequest->setUsername($username);
$authResponse = $authRequest->send();
if ($authResponse->isNotfound()) {
  // user not paired
}
if ($authResponse->isOk())
{
  printf("user notified about possible fraud attempt\n");
}

cancel

To disable the service use the cancel call, no further requests will be accepted by the Sezame servers:

$client = new \SezameLib\Client($certfile, $keyfile, $keyPassword);
$client->cancel()->send();

error handling

The Sezame Lib throws exceptions in the case of an error.

$client = new \SezameLib\Client($certfile, $keyfile);
try {
  $client->cancel()->send();
  printf("Client canceled\n");
} catch (\SezameLib\Exception\Connection $e) {
  printf("Connection failure: %s %d\n",
  $e->getMessage(), $e->getCode());
} catch (\SezameLib\Exception\Parameter $e) {
  print_r($e->getErrorInfo());
} catch (\SezameLib\Exception\Response $e) {
  printf("%s %d\n", $e->getMessage(), $e->getCode());
}

License

This bundle is under the BSD license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.

finpin/sezame-sdk 适用场景与选型建议

finpin/sezame-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 96 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 finpin/sezame-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-03-11