Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/4rthem/request-signer-bundle


https://github.com/4rthem/request-signer-bundle

Last synced: 13 days ago
JSON representation

Awesome Lists containing this project

README

        

# Request signer bundle

This bundle helps you to sign requests in order to provide access to protected resources.

[![Build Status](https://travis-ci.com/4rthem/request-signer-bundle.svg?branch=master)](https://travis-ci.com/4rthem/request-signer-bundle)

## Adapters

Supported providers:

- AWS S3 (composer req arthem/jwt-request-signer)
- Local with JWT (composer req arthem/jwt-request-signer)

## Installation & configuration

```bash
composer require arthem/request-signer-bundle
```

Configure your signers:

```yaml
# config/packages/arthem_request_signer.yaml
services:
s3_client:
class: Aws\S3\S3Client
arguments:
-
region: us-east-2
version: "2006-03-01"
credentials:
key: '%env(AWS_ACCESS_KEY)%'
secret: '%env(AWS_SECRET_KEY)%'

arthem_request_signer:
signers:
my_local_jwt: # your signer name
jwt: # signer adapter
ttl: 120 # in seconds
signing_key: '%env(resolve:MY_SIGNING_KEY)%'
aws_images: # your signer name
aws_s3: # signer adapter
bucket_name: 'my_bucket'
service_id: 's3_client' # id of your s3 client service
```

```dotenv
# .env
MY_SIGNING_KEY=change-me
AWS_ACCESS_KEY=change-me
AWS_SECRET_KEY=change-me
```

## Usage

Sign your asset URLs:

```php
requestSigner->signUri(
$this->urlGenerator->generate('asset_preview', ['id' => $asset->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
$this->requestStack->getCurrentRequest(),
[
'signer' => 'aws_images', // override default adapter (optional)
'ResponseContentDisposition' => 'attachment; filename=image.jpg', // Force S3 download
]
);
}
}
```

If validation is made by your application:

```php
validateRequest($request);
} catch (InvalidSignatureException $e) {
throw new AccessDeniedHttpException($e->getMessage());
}

// Stream asset here
}
}
```