0

Hi I'm trying to get a token from an api but no matter what I try on the droplet I get an invalid client every single time, the code is the same locally and on the droplet, currently working on local but not on the droplet.

This is the code

return Cache::rememberForever('payment_token', function () {
    $client = new Client(['http_errors' => false]);

    $params = [
        'client_id' => env('CLIENT_ID'),
        'client_secret' => env('CLIENT_SECRET'),
        'grant_type' => 'client_credentials',
    ];

    $headers = [
        'Accept' => 'application/json',
    ];

    $response = $client->request('POST', 'https://apipay.io/auth/token/', [
        'json' => $params,
        'headers' => $headers
    ]);

    $res_body = json_decode($response->getBody()->getContents());

    return $res_body->access_token;
});

The url for the post isn't a real one, I don't really think it's wise to post the real one as it doesn't work without the client_id and client_secret which I can't post here.

Is there a reason why the droplet would interfere with this? What can I do to fix this?

Nancy
  • 1,021
  • 4
  • 23
  • 45
  • @MartinZeitler I have it like that if you look, the error doesn't change it says `invalid_client` every time, the URL is `https://api.payments.4geeks.io/authentication/token/` that won't help since you need the client_id and client_secret – Nancy Oct 08 '20 at 19:38
  • @MartinZeitler well I'm using the same test `client_id` and `client_secret` I thought it would work without issues, I didn't read anything in the docs about having to register the host-name. The docs are in Spanish so I'm not sure you want to take a look https://support-payments.4geeks.io/es/latest/iniciar.html#activacion-de-produccion – Nancy Oct 08 '20 at 20:10
  • These are the actual API docs: http://docs.payments.4geeks.io/#authentication and they probably might be able to help you there: https://community.4geeks.io/c/4geeks-payments – Martin Zeitler Oct 08 '20 at 20:32
  • maybe the curl/tls version is different on the droplet. I would try with curl from the terminal and see if it works that way. – adrian7 Oct 08 '20 at 20:34

1 Answers1

1

Double-check the remote .env file and make sure, that it's not some outdated, cached version of it (which env() would then return). Laravel has this feature, which can indeed be quite tricky, while not considering that (eg. it just doesn't work for no apparent reason). php artisan cache:clear clears the config-cache and php artisan config:cache builds it up again; I even think that production uses a cached config by default (which may be the actual difference there).

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Yea I had to check a couple times, the `client_id` and `client_secret` in my editor the capital O and the 0 look almost exactly the same, I'm sure I had the two mixed up somewhere I rewrote it again and now it's working. – Nancy Oct 08 '20 at 22:04
  • Access credentials are one of the cases where copy & paste is perfectly fine, if not to be preferred. – Martin Zeitler Oct 08 '20 at 22:27