sunkan / aws-auth-policy
库,用于帮助生成 AWS Gateway API Authorizers 的认证策略
1.0.0
2024-02-12 11:53 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^11.0
README
安装
$ composer require sunkan/aws-auth-policy
用法
use Sunkan\AwsAuthPolicy\AuthPolicy; $policy = new AuthPolicy( 'me', '50505050', [ 'region' => 'eu-west-1', 'stage' => 'prod', ], ); $policy->allowAll(); echo json_encode($policy->build());
与 Bref 一起使用
use Bref\Context\Context; use Bref\Event\Handler; use Sunkan\AwsAuthPolicy\AuthPolicy; final class AuthorizerAction implements Handler { public function handle($event, Context $context) { $policy = AuthPolicy::fromMethodArn($event['methodArn']); // validate $event['authorizationToken'] if ($validToken) { $policy->allowAll(); } else { $policy->denyAll(); } return $policy; } }