0

based on Documentation I've tried to make GET request. When I make GET request through the POSTMAN app, it works fine and it returns me proper respond, but when I try to make the same call through php(Laravel) I get 401 error code.

my code for basic Auth looks like this:

   namespace App;
   use GuzzleHttp\Client;

    class Api extends Model
    {
        static function TiktalikRespond(){
            $client = new Client();
            $base_encode = base64_encode(username:password);

            $res = $client->get(
                   'https://www.tiktalik.com/api/v1/computing/instance',
                   ['headers' => ['Authorization' => 'Basic '.$base_encode]]
            );

            $respond = $res->getBody();

            return json_decode($respond);
        }
    }

my code for API key looks like this:

namespace App;
use GuzzleHttp\Client;

class Api extends Model
{
    static function TiktalikRespond2(){
        $client = new Client();
        $sha1 = hash_hmac('sha1',
                          'GET \n \n application\json \n X-TK-Date \n https://www.tiktalik.com/api/v1/computing/instance',
                          'private_api_key');

        $res = $client->get(
               'https://www.tiktalik.com/api/v1/computing/instance',
               ['headers' => ['Authorization' => 'TKAuth API_KEY:'.$sha1]]
        );

        $respond = $res->getBody();

        return json_decode($respond);
    }
}

I need a fresh look maybe I've done something wrong :)

PS. API Auth doesn't work for both cases, PHP and POSTMAN, I'm guessing that I messed up something with SHA1 value :)

Sharminte
  • 3
  • 7
  • Check this [How do i do HTTP basic authentication using Guzzle?](https://stackoverflow.com/questions/30970736/how-do-i-do-http-basic-authentication-using-guzzle) – yip102011 Jan 17 '19 at 04:13
  • i've tried avery single 1 method from post which you mentioned, none of them works ;/ still get Code 401 – Sharminte Jan 17 '19 at 04:28
  • you said it works fine on POSTMAN, would you post the info when using postman? http header, http method(GET/POST), url. – yip102011 Jan 17 '19 at 06:43
  • `Authorization:Basic encoded_password` this is all i'm sending with GET request throuth POSTMAN for this url `https://www.tiktalik.com/api/v1/computing/instance` end with that i receive status 200 – Sharminte Jan 17 '19 at 08:46

0 Answers0