Skip to content

Commit ea50417

Browse files
authored
Merge pull request #423 from patrickcarlohickman/add-null-authenticator
Feature | Add a `NullAuthenticator` to overwrite defaultAuth
2 parents 29ced5f + 528dd23 commit ea50417

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Saloon\Http\Auth;
6+
7+
use Saloon\Http\PendingRequest;
8+
use Saloon\Contracts\Authenticator;
9+
10+
class NullAuthenticator implements Authenticator
11+
{
12+
/**
13+
* Apply the authentication to the request.
14+
*/
15+
public function set(PendingRequest $pendingRequest): void
16+
{
17+
//
18+
}
19+
}

tests/Unit/AuthenticatesRequestsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use GuzzleHttp\RequestOptions;
66
use Saloon\Exceptions\SaloonException;
7+
use Saloon\Http\Auth\NullAuthenticator;
78
use Saloon\Http\Auth\MultiAuthenticator;
89
use Saloon\Http\Auth\TokenAuthenticator;
910
use Saloon\Http\Auth\HeaderAuthenticator;
1011
use Saloon\Tests\Fixtures\Requests\UserRequest;
1112
use Saloon\Tests\Fixtures\Connectors\ArraySenderConnector;
13+
use Saloon\Tests\Fixtures\Connectors\DefaultAuthenticatorConnector;
1214

1315
test('you can add basic auth to a request', function () {
1416
$request = new UserRequest;
@@ -106,3 +108,14 @@
106108
'X-API-Key' => 'api-key',
107109
]);
108110
});
111+
112+
test('you can use a null authenticator to disable default authentication entirely', function () {
113+
$connector = new DefaultAuthenticatorConnector;
114+
$request = new UserRequest;
115+
116+
$request->authenticate(new NullAuthenticator);
117+
118+
$pendingRequest = $connector->createPendingRequest($request);
119+
120+
expect($pendingRequest->headers()->all())->toEqual(['Accept' => 'application/json']);
121+
});

0 commit comments

Comments
 (0)