saloon icon indicating copy to clipboard operation
saloon copied to clipboard

Best method for AWS SigV4 signing

Open willvincent opened this issue 11 months ago • 0 comments

It appears as though only PendingRequest is available to the Authenticator interface.

Unfortunately, the AWS sdk requires the psr http-message RequestInterface to sign a request. As such it seems that the best (and perhaps only) method available to do sign requests for aws is to add the handlePsrRequest method to the connector or request class.

I'm just wondering if there's a cleaner way to do this with the authenticator interface, which seems like it'd be the better place to add the signatures, though it's not clear how I'd accomplish it.

Within the handlePsrRequest method though, it looks like I can simply do this:

use Aws\Credentials\Credentials;
use Aws\Signature\SignatureV4;

public function handlePsrRequest(RequestInterface $request, PendingRequest $pendingRequest): RequestInterface
{
    $signature = new SignatureV4('execute-api', 'us-east-1');
    $credentials = new Credentials('MY_IAM', 'MY_SECRET_KEY');

    return $signature->signRequest($request, $credentials);
}

If this can be handled through an authenticator that'd be ideal, but either way - it'd be good to get some documentation in place, I can't imagine I'm the only person to want to use Saloon with an AWS ApiGateway api.

willvincent avatar Feb 13 '25 17:02 willvincent