Skip to content

Commit 76fb861

Browse files
committed
fix AntiForgery naming
1 parent 75f33a4 commit 76fb861

12 files changed

+43
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This dependency is a part of **DevNet Framework**, which includes the following
1111
- Error Handler
1212
- Authentication
1313
- Authorization
14-
- Antiforgery
14+
- CSRF Prevention
1515

1616
## Requirements
1717
- [DevNet Core](https://github.com/DevNet-Framework/core/) version 1.0

lib/Endpoint/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use DevNet\Web\Endpoint\Results\StatusCodeResult;
1818
use DevNet\Web\Endpoint\Results\ViewResult;
1919
use DevNet\Web\Http\Message\HttpContext;
20-
use DevNet\Web\Security\Tokens\Csrf\IAntiforgery;
20+
use DevNet\Web\Security\Tokens\Csrf\IAntiForgery;
2121
use DevNet\Web\View\ViewManager;
2222

2323
abstract class Controller
@@ -52,9 +52,9 @@ public function view(array $data = [], ?string $name = null): ViewResult
5252
$view = new ViewManager($directory, $this->HttpContext->Services);
5353
$view->inject('User', $this->ActionContext->HttpContext->User);
5454

55-
$antiforgery = $this->ActionContext->HttpContext->Services->getService(IAntiforgery::class);
55+
$antiforgery = $this->ActionContext->HttpContext->Services->getService(IAntiForgery::class);
5656
if ($antiforgery) {
57-
$view->inject('Antiforgery', $antiforgery);
57+
$view->inject('AntiForgery', $antiforgery);
5858
}
5959

6060
return new ViewResult($view($name, $data), 200);

lib/Endpoint/Filters/ValidateAntiForgery.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@
1212
use DevNet\Web\Endpoint\ActionContext;
1313
use DevNet\Web\Endpoint\ActionDelegate;
1414
use DevNet\Web\Endpoint\IActionFilter;
15-
use DevNet\Web\Security\Tokens\Csrf\AntiforgeryException;
16-
use DevNet\Web\Security\Tokens\Csrf\IAntiforgery;
15+
use DevNet\Web\Security\Tokens\Csrf\AntiForgeryException;
16+
use DevNet\Web\Security\Tokens\Csrf\IAntiForgery;
1717
use Attribute;
1818

1919
#[Attribute]
2020
class ValidateAntiForgery implements IActionFilter
2121
{
2222
public function __invoke(ActionContext $context, ActionDelegate $next): Task
2323
{
24-
$antiforgery = $context->HttpContext->Services->getService(IAntiforgery::class);
24+
$antiforgery = $context->HttpContext->Services->getService(IAntiForgery::class);
2525
if (!$antiforgery) {
26-
throw new AntiforgeryException("Unable to get IAntiforgery service, make sure to register it as a service!");
26+
throw new AntiForgeryException("Unable to get IAntiForgery service, make sure to register it as a service!");
2727
}
2828

2929
$result = $antiforgery->validateToken($context->HttpContext);
3030

3131
if (!$result) {
32-
throw new AntiforgeryException("Invalid Antiforgery Token!", 403);
32+
throw new AntiForgeryException("Invalid AntiForgery Token!", 403);
3333
}
3434

3535
return $next($context);

lib/Extensions/ServiceCollectionExtensions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
use DevNet\Web\Http\Message\HttpContext;
1818
use DevNet\Web\Http\Client\HttpClient;
1919
use DevNet\Web\Http\Client\HttpClientOptions;
20-
use DevNet\Web\Security\Tokens\Csrf\IAntiforgery;
21-
use DevNet\Web\Security\Tokens\Csrf\Antiforgery;
22-
use DevNet\Web\Security\Tokens\Csrf\AntiforgeryOptions;
20+
use DevNet\Web\Security\Tokens\Csrf\IAntiForgery;
21+
use DevNet\Web\Security\Tokens\Csrf\AntiForgery;
22+
use DevNet\Web\Security\Tokens\Csrf\AntiForgeryOptions;
2323
use DevNet\Web\Security\Authentication\Authentication;
2424
use DevNet\Web\Security\Authentication\AuthenticationBuilder;
2525
use DevNet\Web\Security\Authentication\IAuthentication;
@@ -45,14 +45,14 @@ public static function addHttpClient(IServiceCollection $services, Closure $conf
4545
$services->addSingleton(HttpClient::class, fn (): HttpClient => new HttpClient($options));
4646
}
4747

48-
public static function addAntiforgery(IServiceCollection $services, Closure $configure = null)
48+
public static function addAntiForgery(IServiceCollection $services, Closure $configure = null)
4949
{
50-
$options = new AntiforgeryOptions();
50+
$options = new AntiForgeryOptions();
5151
if ($configure) {
5252
$configure($options);
5353
}
5454

55-
$services->addSingleton(IAntiforgery::class, fn (): IAntiforgery => new Antiforgery($options));
55+
$services->addSingleton(IAntiForgery::class, fn (): IAntiForgery => new AntiForgery($options));
5656
}
5757

5858
public static function addAuthentication(IServiceCollection $services, Closure $configure)

lib/Security/Tokens/Csrf/Antiforgery.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,38 @@
1111
use DevNet\System\PropertyTrait;
1212
use DevNet\Web\Http\Message\HttpContext;
1313

14-
class Antiforgery implements IAntiforgery
14+
class AntiForgery implements IAntiForgery
1515
{
1616
use PropertyTrait;
1717

18-
private AntiforgeryOptions $options;
19-
private AntiforgeryTokenGenerator $generator;
20-
private AntiforgeryTokenStore $store;
18+
private AntiForgeryOptions $options;
19+
private AntiForgeryTokenGenerator $generator;
20+
private AntiForgeryTokenStore $store;
2121

22-
public function __construct(AntiforgeryOptions $options)
22+
public function __construct(AntiForgeryOptions $options)
2323
{
2424
if ($options->Cookie->HttpOnly === null) {
2525
$options->Cookie->HttpOnly = true;
2626
}
2727

2828
$this->options = $options;
29-
$this->generator = new AntiforgeryTokenGenerator();
30-
$this->store = new AntiforgeryTokenStore($options);
29+
$this->generator = new AntiForgeryTokenGenerator();
30+
$this->store = new AntiForgeryTokenStore($options);
3131
}
3232

33-
public function get_Options(): AntiforgeryOptions
33+
public function get_Options(): AntiForgeryOptions
3434
{
3535
return $this->options;
3636
}
3737

38-
public function getToken(): AntiforgeryToken
38+
public function getToken(): AntiForgeryToken
3939
{
4040
$token = $this->store->getCookieToken();
4141
if ($token) {
4242
return $token;
4343
}
4444

45-
$token = new AntiforgeryToken();
45+
$token = new AntiForgeryToken();
4646
$this->store->saveCookieToken($token);
4747
return $token;
4848
}

lib/Security/Tokens/Csrf/AntiforgeryException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
use Exception;
1212

13-
class AntiforgeryException extends Exception
13+
class AntiForgeryException extends Exception
1414
{
1515
}

lib/Security/Tokens/Csrf/AntiforgeryOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use DevNet\System\Runtime\LauncherProperties;
1212
use DevNet\Web\Http\Message\CookieOptions;
1313

14-
class AntiforgeryOptions
14+
class AntiForgeryOptions
1515
{
1616
public CookieOptions $Cookie;
17-
public string $CookieName = "Antiforgery";
17+
public string $CookieName = "AntiForgery";
1818
public string $FieldName = "X-CSRF-TOKEN";
1919
public string $HeaderName = "X-XSRF-TOKEN";
2020

lib/Security/Tokens/Csrf/AntiforgeryToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use DevNet\System\PropertyTrait;
1212

13-
class AntiforgeryToken
13+
class AntiForgeryToken
1414
{
1515
use PropertyTrait;
1616

lib/Security/Tokens/Csrf/AntiforgeryTokenGenerator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
use DevNet\Web\Http\Message\HttpContext;
1212

13-
class AntiforgeryTokenGenerator
13+
class AntiForgeryTokenGenerator
1414
{
15-
public function generateCookieToken(): AntiforgeryToken
15+
public function generateCookieToken(): AntiForgeryToken
1616
{
17-
return new AntiforgeryToken();
17+
return new AntiForgeryToken();
1818
}
1919

20-
public function generateRequestToken(string $cookieToken): AntiforgeryToken
20+
public function generateRequestToken(string $cookieToken): AntiForgeryToken
2121
{
22-
return new AntiforgeryToken($cookieToken);
22+
return new AntiForgeryToken($cookieToken);
2323
}
2424

2525
public function matchTokens(HttpContext $httpContext, $tokens): bool

lib/Security/Tokens/Csrf/AntiforgeryTokenSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace DevNet\Web\Security\Tokens\Csrf;
1010

11-
class AntiforgeryTokenSet
11+
class AntiForgeryTokenSet
1212
{
1313
public ?string $CookieToken;
1414
public ?string $RequestToken;

0 commit comments

Comments
 (0)