legalthings/authorizer
Composer 安装命令:
composer require legalthings/authorizer
包简介
Authorizer for HTTP requests
README 文档
README
With the authorizer library, a webservice can generate an access token for a resource. The library uses public key cryptography to encrypt the access token. This means it can only be used by a system that has the private decryption key to get access to the resource.
Requirements
- PHP >= 5.5.0
Required PHP extensions are marked by composer
Installation
The library can be installed using composer.
composer require legalthings/authorizer
How it works
System A has a resource which requires authorization. It will only allow system B access to the resource. Clients are allowed to use the resource, but don't have direct access to it. A client using both system A and system B, wants system A to share a specific resource with system B.
Upon request by the client, system A will generate an access token for the resource. It download the public encryption key of system B and uses it to encrypt the access token. This encrypted token returned to the client.
The client passes the link to the resource and the encrypted token to system B. Sytem B will decrypt the encrypted token and use it to download the resource.
Example
System A (has resources)
use LegalThings/Authorizer; Authorizer::$globalSecret = 'some-secret-which-stays-the-same'; $pdf = basename($_GET['pdf']); if (isset($_GET['authzgen'])) { if (parse_url($_GET['authzgen'], PHP_URL_HOST) !== 'system-b.example.com') { http_response_code(403); echo "Will only grant access for system-b.example.com"; exit(); } $encryptedToken = Authorizer::sign($pdf, $_GET['authzgen']); // authzgen is a string with the format: {{public_key_url}};{{time_from}};{{time_to}} header('Content-Type: text/plain'); echo $encryptedToken; exit(); } $mayAccess = isset($_GET['authz']) && Authorizer::verify($pdf, $_GET['authz']); // authz is the decrypted secret if (!$mayAccess) { http_response_code(403); echo "Access denied"; exit(); } // Get and output resource header('Content-Type: application/pdf'); readfile('path/to/resources/' . $pdf);
System B (can download and use resources)
use LegalThings/Authorizer; $link = $_POST['link']; if (isset($_POST['token'])) { $encryptedToken = $_POST['token']; $token = Authorizer::decrypt($encryptedSecret, 'path/to/private_key.pem'); $link .= (strstr($link, '?') ? '&' : '?') . 'authz=' . $token; } $pdf = file_get_contents($link); // Let's do something with the PDF $username = $_SESSION['username']; file_put_contents("../userdata/$username/" . md5(microtime()) . ".pdf", $pdf);
Client
LINK="http://system-a.example.com/get-pdf.php?pdf=abc.pdf" ENCRYPTED_TOKEN=$(curl --get "$LINK" --data-urlencode "authzgen=http://system-b.example.com/authorizer.pem") curl --post "http://system-b.example.com/use-pdf.php" --data-urlencode "link=$LINK" --data-urlencode "authz=$ENCRYPTED_TOKEN"
Why is this useful?
This is a way to allow two systems to share resources between them, with minimal coupling.
System B can use any PDF on the internet. By implementing Authorizer it gives services that want to share a resource only
with system B the means to do so.
legalthings/authorizer 适用场景与选型建议
legalthings/authorizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 legalthings/authorizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 legalthings/authorizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-19