sunkan / aws-auth-policy
Library to help with generating auth policies for 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
Installation
$ composer require sunkan/aws-auth-policy
Usage
use Sunkan\AwsAuthPolicy\AuthPolicy; $policy = new AuthPolicy( 'me', '50505050', [ 'region' => 'eu-west-1', 'stage' => 'prod', ], ); $policy->allowAll(); echo json_encode($policy->build());
Usage with 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; } }