-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from saloonphp/feature/add-certificate-authen…
…ticator Feature | Added certificate authenticator
- Loading branch information
Showing
8 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Http\Auth; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
use Saloon\Http\PendingRequest; | ||
use Saloon\Contracts\Authenticator; | ||
use Saloon\Http\Senders\GuzzleSender; | ||
use Saloon\Exceptions\SaloonException; | ||
|
||
class CertificateAuthenticator implements Authenticator | ||
{ | ||
/** | ||
* Constructor | ||
*/ | ||
public function __construct( | ||
public string $path, | ||
public ?string $password = null, | ||
) { | ||
// | ||
} | ||
|
||
/** | ||
* Apply the authentication to the request. | ||
* | ||
* @throws \Saloon\Exceptions\SaloonException | ||
*/ | ||
public function set(PendingRequest $pendingRequest): void | ||
{ | ||
if (! $pendingRequest->getConnector()->sender() instanceof GuzzleSender) { | ||
throw new SaloonException('The CertificateAuthenticator is only supported when using the GuzzleSender.'); | ||
} | ||
|
||
// See: https://docs.guzzlephp.org/en/stable/request-options.html#cert | ||
|
||
$path = $this->path; | ||
$password = $this->password; | ||
|
||
$certificate = is_string($password) ? [$path, $password] : $path; | ||
|
||
$pendingRequest->config()->add(RequestOptions::CERT, $certificate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"statusCode":200,"headers":{"Date":"Sat, 02 Dec 2023 16:01:23 GMT","Content-Type":"text\/xml; charset=UTF-8","Content-Length":"1317","Connection":"keep-alive","access-control-allow-origin":"*","Cache-Control":"no-cache, private","x-frame-options":"SAMEORIGIN","x-xss-protection":"1; mode=block","x-content-type-options":"nosniff","CF-Cache-Status":"DYNAMIC","Report-To":"{\"endpoints\":[{\"url\":\"https:\\\/\\\/a.nel.cloudflare.com\\\/report\\\/v3?s=8t7HkDmpXwrJNaQUDwqb6GXENRT2oZt3tqla7AT69PlDzz%2FoF6lUjsYS%2BYYE7%2FR9x3mRtRFgOGqlr0zT0byUcjWetwrtOaO4O%2BGho%2B1Frpk3erLyDD0kQEp6TA%2BhiUqeB%2FSYRXWwO9%2FHohaktPsv\"}],\"group\":\"cf-nel\",\"max_age\":604800}","NEL":"{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}","Server":"cloudflare","CF-RAY":"82f4c9cb9b1f638b-LHR","alt-svc":"h3=\":443\"; ma=86400"},"data":"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<breakfast_menu name=\"Big G's Breakfasts\">\n <food soldOut=\"false\" bestSeller=\"true\">\n <name>Belgian Waffles<\/name>\n <price>$5.95<\/price>\n <description>Two of our famous Belgian Waffles with plenty of real maple syrup<\/description>\n <calories>650<\/calories>\n <\/food>\n <food soldOut=\"false\" bestSeller=\"false\">\n <name>Strawberry Belgian Waffles<\/name>\n <price>$7.95<\/price>\n <description>Light Belgian waffles covered with strawberries and whipped cream<\/description>\n <calories>900<\/calories>\n <\/food>\n <food soldOut=\"false\" bestSeller=\"true\">\n <name>Berry-Berry Belgian Waffles<\/name>\n <price>$8.95<\/price>\n <description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream<\/description>\n <calories>900<\/calories>\n <\/food>\n <food soldOut=\"true\" bestSeller=\"false\">\n <name>French Toast<\/name>\n <price>$4.50<\/price>\n <description>Thick slices made from our homemade sourdough bread<\/description>\n <calories>600<\/calories>\n <\/food>\n <food soldOut=\"false\" bestSeller=\"false\">\n <name>Homestyle Breakfast<\/name>\n <price>$6.95<\/price>\n <description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns<\/description>\n <calories>950<\/calories>\n <\/food>\n<\/breakfast_menu>\n"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters