$ 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());
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;
}
}