patrikgrinsvall / laravel-bankid
Laravel 8 的瑞典 BankId 集成
v0.2.0
2021-06-08 06:47 UTC
Requires
- php: ^7.4 | ^8.0
- illuminate/contracts: ^8.0
- livewire/livewire: ^2.4
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- vimeo/psalm: ^4.4
This package is auto-updated.
Last update: 2024-09-26 18:32:26 UTC
README
虽然这个包是免费的,但您可以通过联系 info@silentridge.io 来获取集成帮助。
Laravel 8 的瑞典 BankID 与 Livewire
您需要 Laravel 8 来使用路由外观,但使用中间件时可能适用于早期版本。Livewire 是必需的依赖项,因此它将被安装。然而,我认为从另一个控制器操作调用该服务相当简单,并且它将工作得很好。
无论如何,这个项目还有很多改进空间,但它至少被一家公司用于生产。PR 非常受欢迎。
安装
Composer
composer require patrikgrinsvall/laravel-bankid
- 使用以下命令发布配置、视图和翻译
php artisan vendor:publish --provider="Patrikgrinsvall\LaravelBankid\LaravelBankidServiceProvider"
- 然后检查
app/config/bankid.php
以获取有关如何添加您自己的证书的信息。 - 视图将在您的视图目录中可编辑
- 翻译将在默认翻译目录中可编辑。该软件包提供了瑞典语和英语。
使用
- 自 Laravel 8 以来,服务提供者应该可以自动发现,因此不需要注册服务提供者。
- 然而,我在许多情况下注意到这不起作用,所以通常
- 在
config/app.php
中注册服务提供者Patrikgrinsvall\LaravelBankid\BankidServiceProvider
使用此包有几种不同的方式
- 使用提供的路由宏
// You can change the route prefix '/bankid' to whatever you want, for example /login.
// This is then the entrypoint for where users should be sent to start authentication.
// This line of code should be placed in routes.
Route::LaravelBankid('/bankid');
- 作为外观(这可能有效,记不清楚了。)
use Patrikgrinsvall\LaravelBankid\BankidFacade;
...
Bankid::login(); // will redirect user and start a login. After login user is returned to url in config/bankid.php
Bankid::user(); // returns the user previously logged in or false.
- 作为中间件,首先在
App\Http\Kernel
类中注册:(WIP!不要使用!)
protected $routeMiddleware = [
'bankid' => \Patrikgrinsvall\LaravelBankid\BankidMiddleware::class,
然后按照以下方式使用
// On a single route
Route::get('/profile', function () {
// your stuff
})->middleware('bankid');
// On a group of routes
Route::middleware([BankidMiddleware::class])->group(function () {
Route::get('/your-route', View::render('your-route'))
});
// On a group of routes without adding to kernel
Route::middleware([\Patrikgrinsvall\LaravelBankid\BankidMiddleware::class])->group(function () {
Route::get('/your-route', View::render('your-route'))
});
检索已认证用户。
// Get the user from the session
use Illuminate\Support\Facades\Session;
...
Session::get('bankid.user'); // returns user details as an array
Session::get('bankid.personalNumber'); // returns personal number as a string
Session::get('bankid.name'); // returns full name as a string
Session::get('bankid.givenName'); // returns first name as a string
Session::get('bankid.surname'); // returns lastn name as string
Session::get('bankid.signature'); // returns signature as string.
从外观
use Patrikgrinsvall\LaravelBankid\BankidFacade;
...
Bankid::user();
测试
composer test
最后备注。
- 基本身份验证适用于移动设备。
- 但这个包中有很多东西还没有完成,我将在需要时继续迭代它。
- PR 非常受欢迎!
- 签名不起作用。
- 二维码不起作用。
- 同一设备不起作用(银行 ID 在文件中)
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件