mvieira/macaroons
Composer 安装命令:
composer require mvieira/macaroons
包简介
README 文档
README
A php implementation of Macaroons: Cookies with Contextual Caveats for Decentralized Authorization
Specification
Resources
- http://hackingdistributed.com/2014/05/21/my-first-macaroon/
- https://air.mozilla.org/macaroons-cookies-with-contextual-caveats-for-decentralized-authorization-in-the-cloud/
- https://evancordell.com/2015/09/27/macaroons-101-contextual-confinement.html
Installation
Requirements
- php >= 7.0
- libsodium-php >= 1.0
About libsodium
- The
libsodiumlibrary will be distributed with PHP >= 7.2) - The
libsodiumlibrary is not required incomposer.jsonbecause the versions 1 (ext-libsodium) and 2 (ext-sodium) have different names. Nevertheless, this package should work with both once installed.
Installation
Add the library as a requirement in your composer.json
{
"require": {
"mvieira/macaroons": "dev-master"
}
}
or with command line
$ composer require mvieira/macaroons
Documentation
Here is a simple example with a third party macaroon:
On the target service server, produce the macaroon authorizing the user to access the service.
use Macaroons\Macaroon; use function Macaroons\Crypto\crypto_gen_nonce; $macaroon = Macaroon::create('secret random number', crypto_gen_nonce(), 'https://unicorn.co'); $macaroon = $macaroon ->withThirdPartyCaveat('third party secret', 'user_auth', 'https://auth.unicorn.co');
On the identification provider server, produce the discharge macaroon that will verified the third party caveat
use Macaroons\Macaroon; // user login happens beforehand... // once the user manages to log in to the service // Deserialize the root macaroon $macaroon = Macaroon::deserialize('@#!?$'); // prepare the discharge macaroon that will satisfied the third party caveat $discharge = Macaroon::create('third party secret', 'user_auth', 'https://auth.unicorn.co') ->withFirstPartyCaveat('user_id = 12345678'); // add the requested first party caveat // bind the discharge macaroon to the root macaroon $discharge = $macaroon->bind($discharge);
Back on the target service server
use Macaroons\Macaroon; use Macaroons\Verifier; use Macaroons\Serialization\V1\Serializer; // deserialize both macaroons $macaroon = Macaroon::deserialize('@#!?$', new Serializer()); $discharge = Macaroon::deserialize('#?@$!', new Serializer()); // prepare the verifier $verifier = (new Verifier()) ->satisfyExact('user_id = 12345678') ->withDischargeMacaroon($discharge); try { $verified = $macaroon->verify('secret random number', $verifier); } catch (\DomainException $e) { // Catch verification errors echo $e->getMessage() . "\n"; }
Examples
Examples are available in the directory ./examples/
$ php ./examples/1-target-service.php
$ php ./examples/2-identity-provider.php
$ php ./examples/3-verification.php
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see LICENSE for more information.
mvieira/macaroons 适用场景与选型建议
mvieira/macaroons 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.47k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「authorization」 「Authentication」 「cookie」 「macaroon」 「caveats」 「decentralization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mvieira/macaroons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mvieira/macaroons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mvieira/macaroons 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
统计信息
- 总下载量: 5.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-04