Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/4rthem/request-signer-bundle
https://github.com/4rthem/request-signer-bundle
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/4rthem/request-signer-bundle
- Owner: 4rthem
- Created: 2020-04-01T14:08:20.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T20:32:07.000Z (almost 2 years ago)
- Last Synced: 2024-11-10T13:43:58.558Z (2 months ago)
- Language: PHP
- Size: 105 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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
}
}
```