You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-26Lines changed: 16 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,19 @@
1
1
# 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.**
3
3
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 .
5
5
6
-
Features:
7
-
* URL generation in .twig-Files
6
+
**Features:**
7
+
* URL generation in Twig Templates
8
8
* 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
11
11
12
12
## Installation
13
-
The best way to install this bundle is via composer in your Symfony 4 Framework:
- 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
-
```
27
17
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:
28
18
29
19
```php
@@ -35,15 +25,16 @@ return [
35
25
```
36
26
37
27
## 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:
40
30
```twig
41
-
<!-- Generating a regular link -->
31
+
<!-- Generating a link -->
42
32
<a href="{{ path('member_detail', { id: user.id }) }}">A Link </a>
43
33
44
34
<!-- A link with a hash signature -->
45
35
<a href="{{ signed_url('member_detail', { id: user.id }) }}">A Link with a signature</a>
46
36
```
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.
47
38
48
39
To set an expire date for an URL, pass the date as the 3rd parameter:
49
40
```html
@@ -54,6 +45,8 @@ The expiration value can be
54
45
* a \DateTime object
55
46
* a timestamp as integer
56
47
48
+
If the hash value is validated AFTER the expiration time, it is invalid.
49
+
57
50
### Sign URLs in your controller
58
51
Use dependency injection to get an instance of `Shift\UrlSignatureBundle\Utils\UrlSignatureBuilder`:
59
52
@@ -97,10 +90,10 @@ class ExampleController extends AbstractController
97
90
// is Signature missing or invalid? Show an alert, redirect or do something you like
98
91
}
99
92
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.
101
95
$signatureValidator->verify();
102
96
103
-
104
97
// There is no need to also inject the request object to your
105
98
// action method as it is provided by RequestValidator instance.
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.
198
191
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
-
202
192
## Submitting bugs and feature requests
203
193
Bugs and feature request are tracked on GitHub.
204
194
@@ -210,7 +200,7 @@ Bugs and feature request are tracked on GitHub.
0 commit comments