akaunting/signed-url
最新稳定版本:1.0.0
Composer 安装命令:
composer require akaunting/signed-url
包简介
Signed (unique) URL package for Laravel.
README 文档
README
This package can create URLs with a limited lifetime. This is done by adding an expiration date and a signature to the URL.
This is how you can create signed URL that's valid for 30 days:
SignedUrl::sign('https://myapp.com/protected-route', 30);
The output will look like this:
https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx
The URL can be validated with the validate-function.
SignedUrl::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');
The package also provides a middleware to protect routes.
Installation
As you would have guessed the package can be installed via Composer:
composer require akaunting/signed-url
This package intends to provide tools for formatting and conversion monetary values in an easy, yet powerful way for Laravel projects. In older versions of the framework, just add the serviceprovider, and optionally register the facade:
// config/app.php 'providers' => [ ... Akaunting\SignedUrl\Provider::class, ]; 'aliases' => [ ... 'SignedUrl' => Akaunting\SignedUrl\Facade::class, ];
Configuration
The configuration file can optionally be published via:
php artisan vendor:publish --provider=signed-url
This is the content of the file:
return [ /* * This string is used the to generate a signature. You should * keep this value secret. */ 'signatureKey' => env('APP_KEY'), /* * The default expiration time of a URL in days. */ 'default_expiration_time_in_days' => 1, /* * These strings are used a parameter names in a signed url. */ 'parameters' => [ 'expires' => 'expires', 'signature' => 'signature', ], /* |-------------------------------------------------------------------------- | Middleware |-------------------------------------------------------------------------- | | This option indicates the middleware to change language. | */ 'middleware' => 'Akaunting\SignedUrl\Middleware\ValidateSignedUrl', ];
Usage
Signing URLs
URL's can be signed with the sign-method:
SignedUrl::sign('https://myapp.com/protected-route');
By default the lifetime of an URL is one day. This value can be change in the config-file. If you want a custom life time, you can specify the number of days the URL should be valid:
//the generated URL will be valid for 5 days. SignedUrl::sign('https://myapp.com/protected-route', 5);
For fine grained control, you may also pass a DateTime instance as the second parameter. The url
will be valid up to that moment. This example uses Carbon for convenience:
//This URL will be valid up until 2 hours from the moment it was generated. SignedUrl::sign('https://myapp.com/protected-route', Carbon\Carbon::now()->addHours(2) );
Validating URLs
To validate a signed URL, simply call the validate()-method. This return a boolean.
SignedUrl::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');
Protecting routes with middleware
The package also provides a middleware to protect routes:
Route::get('protected-route', ['middleware' => 'signed', function () { return 'Hello secret world!'; }]);
Your app will abort with a 403 status code if the route is called without a valid signature.
Changelog
Please see Releases for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email security@akaunting.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
akaunting/signed-url 适用场景与选型建议
akaunting/signed-url 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.9k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2018 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「url」 「laravel」 「signed」 「unique」 「unique link」 「unique url」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 akaunting/signed-url 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 akaunting/signed-url 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 akaunting/signed-url 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A wrapper to add the ability to accept signed requests to a Laravel project.
Sign and verify HTTP messages with Guzzle
Easy URL rewrites in your Laravel application
Simple encoding/decoding of data and hash validation using a shared secret
Storageless sessions with encrypted and HMAC-signed cookies
A Laravel helper to detect if the current route/path is active.
统计信息
- 总下载量: 13.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-11