Skip to content

Library to help with generating auth policies for AWS Gateway API Authorizers

License

Notifications You must be signed in to change notification settings

sunkan/aws-auth-policy

Repository files navigation

Aws Auth Policy

Latest Version on Packagist Software License Build Status Coverage Status

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;
    }
}

About

Library to help with generating auth policies for AWS Gateway API Authorizers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages