Skip to content

Commit 05aa91c

Browse files
author
Daniel Sentker
committed
Updated Readme
1 parent 588249c commit 05aa91c

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

README.md

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
# URL Signature Bundle
2-
**A Symfony4 bundle for the [url-signature](https://github.com/dsentker/url-signature) library.**
2+
**A Symfony 4 bundle for the [url-signature](https://github.com/dsentker/url-signature) library.**
33

4-
This bundle allows you to build urls with a signature un query string to prevent the modification of URL parts form a user. For a more detailed description, view the README from [url-signature](https://github.com/dsentker/url-signature) library .
4+
This bundle allows you to build URLs with a signature in query string to prevent the modification of URL parts form a user. For a more detailed description, view the README from [url-signature](https://github.com/dsentker/url-signature) library .
55

6-
Features:
7-
* URL generation in .twig-Files
6+
**Features:**
7+
* URL generation in Twig Templates
88
* URL generation and URL validation with a controller helper trait
9-
* URL generation and URL validation with action-based Dependency Injection in your controllers
10-
* URL validation with Annotation support
9+
* URL generation and URL validation with Dependency Injection in your controllers
10+
* URL validation in your controller with Annotation
1111

1212
## Installation
13-
The best way to install this bundle is via composer in your Symfony 4 Framework:
13+
Use composer to install this bundle:
1414
```composer
1515
require dsentker/url-signature-bundle
1616
```
17-
...which results in:
18-
```composer log
19-
Package operations: 1 install, 0 updates, 0 removals
20-
- Installing dsentker/url-signature-bundle (0.0.1): Downloading (100%)
21-
[...]
22-
Symfony operations: 1 recipe
23-
- Configuring dsentker/url-signature-bundle (>=0.0.1): From auto-generated recipe
24-
Executing script cache:clear [OK]
25-
Executing script assets:install public [OK]
26-
```
2717
If you use Symfony Flex, you do not have to do anything anymore. Otherwise you have to include the bundle in your `<root>/config/bundles.php` like this:
2818

2919
```php
@@ -35,15 +25,16 @@ return [
3525
```
3626

3727
## Usage
38-
### Sign URLs in your Twig Template
39-
This bundle comes with a twig function to create an url from any route name: `signed_url()` (and, as alias, `signed_path()`) works just like the symfony / twig function `path()` which you have certainly used a hundredfold. signed_path expects a route name and, optionally, query data as array:
28+
### Create signed URLs in your Twig Template
29+
This bundle comes with a twig extension to create an url from any route name: `signed_url()` (and, as alias, `signed_path()`) works just like the symfony / twig function `path()` which you have certainly used a hundredfold. `signed_path` expects a route name as first argument and, optionally, query data as array:
4030
```twig
41-
<!-- Generating a regular link -->
31+
<!-- Generating a link -->
4232
<a href="{{ path('member_detail', { id: user.id }) }}">A Link </a>
4333
4434
<!-- A link with a hash signature -->
4535
<a href="{{ signed_url('member_detail', { id: user.id }) }}">A Link with a signature</a>
4636
```
37+
Both links lead to the same target, but the link created via `signed_url(...)` has a hash in the query string. This hash can be validated in the destination controller.
4738

4839
To set an expire date for an URL, pass the date as the 3rd parameter:
4940
```html
@@ -54,6 +45,8 @@ The expiration value can be
5445
* a \DateTime object
5546
* a timestamp as integer
5647

48+
If the hash value is validated AFTER the expiration time, it is invalid.
49+
5750
### Sign URLs in your controller
5851
Use dependency injection to get an instance of `Shift\UrlSignatureBundle\Utils\UrlSignatureBuilder`:
5952

@@ -97,10 +90,10 @@ class ExampleController extends AbstractController
9790
// is Signature missing or invalid? Show an alert, redirect or do something you like
9891
}
9992

100-
// Will throw an Exception if the signature is missing or invalid
93+
// Alternatively, you can use this method. It throws an exception if the hash value
94+
// is missing or not valid.
10195
$signatureValidator->verify();
10296

103-
10497
// There is no need to also inject the request object to your
10598
// action method as it is provided by RequestValidator instance.
10699
$request = $signatureValidator->getRequest();
@@ -196,9 +189,6 @@ shift_url_signature.configuration.default:
196189
```
197190
Do not be surprised at the weird looking arguments for the `setHashMask` method - I did not find a better solution to set a bitmask in a services.yaml.
198191

199-
## Credits
200-
Based on the ideas by [psecio](https://github.com/psecio), the project was forked by [dsentker](https://github.com/dsentker) (thats me 😁) to upgrade the code for PHP 7.x applications. The adjustments then resulted in a separate library and, additionally, in this symfony 4 bundle.
201-
202192
## Submitting bugs and feature requests
203193
Bugs and feature request are tracked on GitHub.
204194

@@ -210,7 +200,7 @@ Bugs and feature request are tracked on GitHub.
210200
phpunit Shift/UrlSignatureBundle/Tests
211201
```
212202

213-
Or, if you prefer Windows:
203+
Or, if you use Windows:
214204
```shell
215205
.\vendor\bin\phpunit.bat Shift/UrlSignatureBundle/Tests/ --configuration phpunit.xml
216206
```

0 commit comments

Comments
 (0)