Unauthorized Exception while Sending a WhatsApp Message
MajdTaweel opened this issue · 3 comments
Expected Behavior
Sending a WhatsApp message through the messaging API should work.
Current Behavior
The following exception is raised:
Vonage\Client\Exception\Request Unauthorised: Request header 'Authorization' missing.
Possible Solution
Comparing version 4.0.0 and 3.1.6, the following code were removed from the file src/Client.php
starting from line 456. I could not see where this logic were moved or if it was replaced with something that provides the credentials for a key pair of application id and private key. By restoring these changes in my local vendor package, the client worked as before.
if ($this->credentials instanceof Container) {
if ($this->needsKeypairAuthentication($request)) {
$handler = new KeypairHandler();
$request = $handler($request, $this->getCredentials());
} else {
$request = self::authRequest($request, $this->credentials->get(Basic::class));
}
} elseif ($this->credentials instanceof Keypair) {
$handler = new KeypairHandler();
$request = $handler($request, $this->getCredentials());
} elseif ($this->credentials instanceof SignatureSecret) {
$request = self::signRequest($request, $this->credentials);
} elseif ($this->credentials instanceof Basic) {
$request = self::authRequest($request, $this->credentials);
}
Steps to Reproduce (for bugs)
$keypair = new \Vonage\Client\Credentials\Keypair(
PRIVATE_KEY,
APPLICATION_ID,
);
$client = new \Vonage\Client($keypair);
$whatsAppText = new \Vonage\Messages\Channel\WhatsApp\WhatsAppText(
FROM_NUMBER,
TO_NUMBER,
'this is a WA text from vonage'
);
$client->messages()->send($whatsAppText);
Your Environment
- Version used: 4.0.4
- PHP 8.1
This is likely to be a bug with the new AuthHandler system which now takes care of adding auth headers - this is why that chunk of code was removed. APIResource
now handles client calls' auth. I'll see if I can reproduce the original problem, as that code that was deleted will almost certainly not be reinstated
This is likely to be a bug with the new AuthHandler system which now takes care of adding auth headers - this is why that chunk of code was removed.
APIResource
now handles client calls' auth. I'll see if I can reproduce the original problem, as that code that was deleted will almost certainly not be reinstated
Thanks for the clarification. For now I've applied a composer patch that adds the removed chunk of code back, since that works for me.
Fixed with the release of 4.0.5, thank you!