Skip to content

Commit

Permalink
Add authorization token on request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
vluzrmos committed Jun 23, 2021
1 parent d800254 commit e79ec5d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Vluzrmos/SlackApi/SlackApi.php
Expand Up @@ -175,7 +175,7 @@ public function setClient($client = null)
{
if (is_callable($client)) {
$this->client = value($client);
} elseif (is_null($client) and is_null($this->client)) {
} elseif (is_null($client) && is_null($this->client)) {
$this->client = new Client(['verify' => false]);
} else {
$this->client = $client;
Expand All @@ -196,15 +196,17 @@ public function setClient($client = null)
*/
protected function http($verb = 'get', $url = '', $parameters = [])
{
$client = $this->getHttpClient();

/* @var \GuzzleHttp\Psr7\Response|\GuzzleHttp\Message\Response $response */
try {
$response = $this->getHttpClient()->$verb($url, $parameters);
$response = $client->$verb($url, $parameters);
} catch (\InvalidArgumentException $e) {
$parameters['body'] = $parameters['form_params'];

unset($parameters['form_params']);

$response = $this->getHttpClient()->$verb($url, $parameters);
$response = $client->$verb($url, $parameters);
}

/** @var $contents */
Expand All @@ -231,12 +233,16 @@ protected function responseToJson($response)
*/
protected function mergeParameters($parameters = [])
{
$options['query'] = [
't' => time(),
'token' => $this->getToken(),
$options = [
'query' => [
't' => time()
],
'headers' => [
'Authorization' => "Bearer {$this->getToken()}"
]
];

if (isset($parameters['attachments']) and is_array($parameters['attachments'])) {
if (isset($parameters['attachments']) && is_array($parameters['attachments'])) {
$parameters['attachments'] = json_encode($parameters['attachments']);
}

Expand Down

0 comments on commit e79ec5d

Please sign in to comment.