Skip to content

Commit 513521f

Browse files
authored
enhancement: treat credential retrieval failures as non-terminal during auth selection (#3106)
1 parent a5e9ba2 commit 513521f

File tree

3 files changed

+19
-45
lines changed

3 files changed

+19
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"type": "bugfix",
4+
"category": "Auth",
5+
"description": "Updates auth selection behavior to treat credential retrieval errors as non-terminal."
6+
}
7+
]

‎src/Auth/AuthSelectionMiddleware.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Aws\Auth;
33

44
use Aws\Api\Service;
5+
use Aws\Auth\Exception\UnresolvedAuthSchemeException;
56
use Aws\CommandInterface;
67
use Closure;
78
use GuzzleHttp\Promise\Promise;
@@ -84,10 +85,16 @@ public function __invoke(CommandInterface $command)
8485
$resolver = $this->authResolver;
8586
}
8687

87-
$selectedAuthScheme = $resolver->selectAuthScheme(
88-
$resolvableAuth,
89-
['unsigned_payload' => $unsignedPayload]
90-
);
88+
try {
89+
$selectedAuthScheme = $resolver->selectAuthScheme(
90+
$resolvableAuth,
91+
['unsigned_payload' => $unsignedPayload]
92+
);
93+
} catch (UnresolvedAuthSchemeException $e) {
94+
// There was an error resolving auth
95+
// The signature version will fall back to the modeled `signatureVersion`
96+
// or auth schemes resolved during endpoint resolution
97+
}
9198

9299
if (!empty($selectedAuthScheme)) {
93100
$command['@context']['signature_version'] = $selectedAuthScheme;

‎tests/Auth/AuthSelectionMiddlewareTest.php

+1-41
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ public function ResolvesAuthSchemeWithoutCRTProvider()
8888
['smithy.api#noAuth'],
8989
'anonymous'
9090
],
91-
[
92-
['aws.auth#sigv4', 'aws.auth#sigv4a'],
93-
['aws.auth#sigv4a'],
94-
'error'
95-
],
9691
];
9792
}
9893

@@ -235,45 +230,10 @@ function () {
235230
);
236231
},
237232
'bearer'
238-
],
239-
[
240-
['aws.auth#sigv4', 'aws.auth#sigv4a'],
241-
['smithy.api#httpBearerAuth'],
242-
function () {
243-
return Promise\Create::promiseFor(
244-
null
245-
);
246-
},
247-
'error'
248-
],
233+
]
249234
];
250235
}
251236

252-
public function testUnknownAuthSchemeThrows()
253-
{
254-
$this->expectException(UnresolvedAuthSchemeException::class);
255-
$this->expectExceptionMessage(
256-
'Could not resolve an authentication scheme: The service does not support `notAnAuthScheme` authentication.'
257-
);
258-
259-
$nextHandler = function (CommandInterface $command) {
260-
return null;
261-
};
262-
$service = $this->generateTestService(['notAnAuthScheme'], []);
263-
$credentialProvider = function () {
264-
return Promise\Create::promiseFor(
265-
null
266-
);
267-
};
268-
$authResolver = new AuthSchemeResolver($credentialProvider);
269-
$client = $this->generateTestClient($service);
270-
$command = $client->getCommand('fooOperation', ['FooParam' => 'bar']);
271-
272-
$middleware = new AuthSelectionMiddleware($nextHandler, $authResolver, $service);
273-
274-
$middleware($command);
275-
}
276-
277237
public function testCommandOverrideResolver()
278238
{
279239
$nextHandler = function (CommandInterface $command) {

0 commit comments

Comments
 (0)