faiaire / laravel-webauthn
Laravel的WebAuthn库
0.1.0
2024-07-22 05:45 UTC
Requires
- php: ^8.2|^8.3
- ext-openssl: *
- 2tvenom/cborencode: ^1.0.2
- illuminate/support: ^10.0|^11.0
- phpseclib/phpseclib: ^3.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0
README
此项目目前正在开发中。
它大量引用以下仓库:https://github.com/davidearl/webauthn
为了获得全面的解决方案,请考虑使用以下稳定适配器:https://github.com/asbiin/laravel-webauthn
此适配器提供了前后端组件的无缝集成。
相比之下,此库仅提供了一个简单的认证门面。
包含的功能
- 后端注册 [x]
- 后端认证 [x]
- 前端注册 []
- 前端认证 []
- 将WebAuthn密钥存储在数据库中 []
要求
- PHP 8.2或更高版本
- Laravel 10.0或更高版本
- ext-openssl
安装
composer require faiare/laravel-webauthn
用法
注册密钥
use Faiare\LaravelWebAuthn\Facades\WebAuthn; $publicKey = WebAuthn::prepareChallengeForRegistration( username: 'username', userid: '100', crossPlatform: true, );
前端示例在examples目录中。
use Faiare\LaravelWebAuthn\Facades\WebAuthn; use Illuminate\Support\Facades\DB; // info must be a string $info = request()->input('credential'); $publicKey = WebAuthn::register($info); // store the public key, example... DB::table('web_authn_keys')->insert([ 'webauthn_id' => $publicKey->webauthnId, 'webauthn_key' => $publicKey->webauthnKey, ]);
认证密钥
use Faiare\LaravelWebAuthn\Facades\WebAuthn; $publicKey = WebAuthn::prepareForAuthenticate();
前端示例在examples目录中。
use Faiare\LaravelWebAuthn\Facades\WebAuthn; use \Illuminate\Support\Facades\DB; // info must be a string $info = request()->input('credential'); $webAuthnId = WebAuthn::parseWebAuthnId($info); // table must have a column named webauthn_id, webauthn_key $webAuthnKey = DB::table('web_authn_keys')->where('webauthn_id', $webAuthnId)->first(); $success = WebAuthn::authenticate($info, $webAuthnKey);