fix signature http/https
This commit is contained in:
parent
69a51c2f07
commit
5af7cddaf9
2 changed files with 11 additions and 8 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Lib\Helpers;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
|
@ -246,7 +245,7 @@ class ToolboxHelper
|
|||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return string request signature
|
||||
* @throws CrmException If an error occurs.
|
||||
* @throws \RuntimeException If an error occurs.
|
||||
*/
|
||||
public static function signRequest(string $secret, string $uri, string $method, array $parameters): string
|
||||
{
|
||||
|
|
@ -302,14 +301,14 @@ class ToolboxHelper
|
|||
));
|
||||
|
||||
if (!$calculatedHash) {
|
||||
throw new Exception('Failed to calculate requests hash');
|
||||
throw new \RuntimeException('Failed to calculate requests hash');
|
||||
}
|
||||
|
||||
return $calculatedHash;
|
||||
} catch (DecryptException $e) {
|
||||
throw new Exception('Failed to decrypt service credentials', 0, $e);
|
||||
throw new \RuntimeException('Failed to decrypt service credentials', 0, $e);
|
||||
} catch (\Exception $e) {
|
||||
throw new Exception('An error occured when authenticating service', 0, $e);
|
||||
}//end try
|
||||
throw new \RuntimeException('An error occured when authenticating service', 0, $e);
|
||||
} //end try
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class Service extends Model
|
|||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return boolean
|
||||
* @throws \App\Exceptions\Api\V2\CrmException If an error occurs.
|
||||
* @throws \RuntimeException If an error occurs.
|
||||
*/
|
||||
public function authenticateApi(Request $request): bool
|
||||
{
|
||||
|
|
@ -125,9 +125,13 @@ class Service extends Model
|
|||
$data = (\is_array($data) and \json_last_error() === \JSON_ERROR_NONE) ?
|
||||
array_replace_recursive($request->all(), $data) : $request->all();
|
||||
|
||||
$uri = $request->getUri();
|
||||
if (app()->environment(['staging', 'production']) and Str::of($uri)->startsWith('http')) {
|
||||
$uri = (string)Str::of($uri)->replaceFirst('http', 'https');
|
||||
}
|
||||
$calculatedHash = ToolboxHelper::signRequest(
|
||||
$this->bearer_pwd,
|
||||
$request->getUri(),
|
||||
$uri,
|
||||
$request->getMethod(),
|
||||
$data
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue