Skip to content

Commit d46e602

Browse files
authored
feat: token (#45)
feat: token
1 parent 191a4c5 commit d46e602

File tree

12 files changed

+60
-14
lines changed

12 files changed

+60
-14
lines changed

docs/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ We will get our copy ready for modifications.
1313
Available options:
1414

1515
- [$expiration](#expiration)
16+
- [$token](#token)
1617
- [$algorithm](#algorithm)
1718
- [$expirationKey](#expirationKey)
19+
- [$tokenKey](#tokenKey)
1820
- [$signatureKey](#signatureKey)
1921
- [$algorithmKey](#algorithmKey)
2022
- [$includeAlgorithmKey](#includeAlgorithmKey)
@@ -28,6 +30,13 @@ It's number of seconds in unix timestamp that will be added to the current date.
2830

2931
By default, this is set to `null`.
3032

33+
### $token
34+
35+
This setting allows us to set a randomly generated token with given length.
36+
It is useful when you have very few changing parameters in the URL.
37+
38+
By default, this is set to `null`.
39+
3140
### $algorithm
3241

3342
This setting allows us to set algorithm that will be used during signing the URLs.
@@ -52,6 +61,16 @@ This is the name of the query string key, which will be responsible for storing
5261

5362
By default, this is set to `expires`.
5463

64+
!!! note
65+
66+
Whatever name you will choose, treat it as a restricted name and don't use it as a part of the query string in your code.
67+
68+
### $tokenKey
69+
70+
This is the name of the query string key, which will be responsible for storing the token string.
71+
72+
By default, this is set to `token`.
73+
5574
!!! note
5675

5776
Whatever name you will choose, treat it as a restricted name and don't use it as a part of the query string in your code.

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ parameters:
88
- vendor/codeigniter4/framework/system/Test/bootstrap.php
99
excludePaths:
1010
ignoreErrors:
11+
- '#Call to deprecated function random_string\(\):#'
1112
universalObjectCratesClasses:
1213
- CodeIgniter\Entity
1314
- CodeIgniter\Entity\Entity

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
<directory suffix=".php">./src/</directory>
2525
</include>
2626
<exclude>
27+
<directory suffix=".php">./src/Commands</directory>
2728
<directory suffix=".php">./src/Config</directory>
28-
<file>./src/Debug/Toolbar.php</file>
29+
<file>./src/Filters/SignedUrl.php</file>
2930
</exclude>
3031
<report>
3132
<clover outputFile="build/phpunit/clover.xml"/>

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
// The paths to refactor (can also be supplied with CLI arguments)
4646
$rectorConfig->paths([
47-
__DIR__ . '/app/',
47+
__DIR__ . '/src/',
4848
__DIR__ . '/tests/',
4949
]);
5050

@@ -111,7 +111,7 @@
111111
* The INLINE_PUBLIC value is default to false to avoid BC break, if you use for libraries and want to preserve BC break, you don't need to configure it, as it included in LevelSetList::UP_TO_PHP_74
112112
* Set to true for projects that allow BC break
113113
*/
114-
TypedPropertyFromAssignsRector::INLINE_PUBLIC => true,
114+
TypedPropertyFromAssignsRector::INLINE_PUBLIC => false,
115115
]);
116116
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
117117
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);

src/Commands/SignedUrlAlgorithms.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
use CodeIgniter\CLI\BaseCommand;
66
use CodeIgniter\CLI\CLI;
77

8-
/**
9-
* @codeCoverageIgnore
10-
*/
118
class SignedUrlAlgorithms extends BaseCommand
129
{
1310
protected $group = 'SignedUrl';

src/Commands/SignedUrlPublish.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use CodeIgniter\Publisher\Publisher;
88
use Throwable;
99

10-
/**
11-
* @codeCoverageIgnore
12-
*/
1310
class SignedUrlPublish extends BaseCommand
1411
{
1512
protected $group = 'SignedUrl';

src/Config/SignedUrl.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class SignedUrl extends BaseConfig
1212
*/
1313
public ?int $expiration = null;
1414

15+
/**
16+
* Length of the token string used with
17+
* random_string() helper. Useful if you have
18+
* very few changing parameters in the URL.
19+
*/
20+
public ?int $token = null;
21+
1522
/**
1623
* Algorithm used to sign the URL.
1724
*
@@ -28,6 +35,7 @@ class SignedUrl extends BaseConfig
2835
*/
2936
public string $expirationKey = 'expires';
3037

38+
public string $tokenKey = 'token';
3139
public string $signatureKey = 'signature';
3240
public string $algorithmKey = 'algorithm';
3341

src/Exceptions/SignedUrlException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public static function forEmptyExpirationKey(): static
2121
return new self(lang('SignedUrl.emptyExpirationKey'));
2222
}
2323

24+
public static function forEmptyTokenKey(): static
25+
{
26+
return new self(lang('SignedUrl.emptyTokenKey'));
27+
}
28+
2429
public static function forEmptySignatureKey(): static
2530
{
2631
return new self(lang('SignedUrl.emptySignatureKey'));

src/Filters/SignedUrl.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* SignedUrl filter.
1515
*
1616
* This filter is not intended to be used from the command line.
17-
*
18-
* @codeCoverageIgnore
1917
*/
2018
class SignedUrl implements FilterInterface
2119
{

src/Language/en/SignedUrl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
'incorrectAlgorithm' => 'Algorithm is incorrect, please run command: "php spark signedurl:algorithms" to see available options.',
55
'invalidAlgorithm' => 'Algorithm is invalid or not supported.',
66
'emptyExpirationKey' => 'Expiration key cannot be empty.',
7+
'emptyTokenKey' => 'Token key cannot be empty.',
78
'emptySignatureKey' => 'Signature key cannot be empty.',
89
'emptyAlgorithmKey' => 'Algorithm key cannot be empty.',
9-
'sameKeyNames' => 'Expiration, Signature or Algorithm keys cannot share the same name.',
10+
'sameKeyNames' => 'Expiration, Token, Signature or Algorithm keys cannot share the same name.',
1011
'emptyEncryptionKey' => 'Encryption key is missing, please run command: "php spark key:generate"',
1112
'missingSignature' => 'This URL have to be signed.',
1213
'urlNotValid' => 'This URL is not valid.',

0 commit comments

Comments
 (0)