finpin / sezame-sdk
无密码多因素认证
0.9.4
2018-06-13 08:49 UTC
Requires
- php: >=5.3.0
- endroid/qr-code: 2.0.*
- kriswallsmith/buzz: 0.15.2
This package is not auto-updated.
Last update: 2024-09-14 11:10:18 UTC
README
无密码多因素认证。
与需要记住另一个PIN或密码的基于密码的解决方案不同,Sezame是一个安全且简单的多因素认证解决方案。您只需要用户名和智能手机上的指纹即可登录任何启用了Sezame的网站。魔法 —— Sezame —— 进入简单!
安装
使用Composer安装库。
$ composer require finpin/sezame-sdk
步骤
要在您的应用程序中使用Sezame,您必须完成以下步骤
- 从应用商店下载并安装Sezame应用程序
- 在应用程序中遵循注册流程
- 注册您的应用程序/客户端
- 获取SSL客户端证书
- 让您的用户将设备与您的应用程序配对
- 发出认证请求
如果您没有带指纹读取器的支持设备,您必须通过Sezame的支持渠道获取ssl证书。
使用
注册
为了能够连接到Sezame HQ服务器,您必须注册您的客户端/应用程序,这通过在应用程序安装过程中输入的恢复电子邮件发送注册调用来完成。您将在Sezame应用程序上收到一个认证请求,必须进行授权。
$client = new \SezameLib\Client(); $registerRequest = $client->register()->setEmail('example@example.com')->setName('my new client'); $registerResponse = $registerRequest->send(); $clientcode = $registerResponse->getClientCode(); $sharedsecret = $registerResponse->getSharedSecret();
签名
在您的移动设备上授权注册后,您可以请求证书。
$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);
在您的系统中存储证书和私钥,建议使用安全的密码短语保护您的私钥。证书和私钥对于后续调用Sezame服务器是必需的,sign和register是唯一两个可以不使用客户端证书进行调用的调用。
配对
成功获得客户端证书后,让您的客户将设备与您的应用程序配对,这是通过显示Sezame应用程序可以读取的QR码来完成的。
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)));
认证
要使用Sezame对用户进行认证,请使用auth调用。
$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); }
欺诈
可以通知用户有关欺诈尝试的情况,如果用户使用密码登录,则可以发送此请求。
$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调用,Sezame服务器将不接受进一步的请求。
$client = new \SezameLib\Client($certfile, $keyfile, $keyPassword); $client->cancel()->send();
错误处理
Sezame库在出现错误时抛出异常。
$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()); }
许可
此捆绑包受BSD许可协议的约束。有关完整的版权和许可信息,请参阅与源代码一起分发的LICENSE文件。