Search code examples
paypalpaypal-sandbox

Connect with PayPal - invalid_client Client Authentication failed with sandbox


I am implementing Connect With PayPal on my vuejs application following this documentation, but I keep getting an invalid_client error when I try to get the access token.

I have created the sandbox REST app on my account and I've enabled "Connect With PayPal". I have also set my return url in the app settings. To build the button I used the button builder and specified my client id, return url and set auth end point as "sandbox". I have added the external script in my index.html and the paypal.use() method in my component.

So now I have the connect button on my interface and when I click on it I am redirected to https://www.sandbox.paypal.com/connect/ which is normal. I can login with my two default sandbox accounts, then I am redirected to the return url that I specified in my app settings, with two url parameters : "code" and "scope" as described in the documentation.

However I am stuck at this step where I need to get an access token for the connected user.

I have tried to run this curl request with my client id / secret and the code from the url but as I said before it doesn't work and I am getting this error everytime :

HTTP/1.1 401 Unauthorized
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Content-Length: 77
Content-Type: application/json
Date: Wed, 08 Jul 2020 22:01:03 GMT
Paypal-Debug-Id: 8abaa5940b688
X-Paypal-Token-Service: IAAS

{
  "error":"invalid_client",
  "error_description":"Client Authentication failed"
}

I have checked my client id and secret multiple times and I can't understand why this is not working, does anyone have an idea ?


Solution

  • Solution for this type of error is to verify and validate everything is being sent correctly in the request, and properly encoded

    curl's -u flag makes username:password header authentication easier

    curl's -v flag will give visibility about the actual communication, to validate