cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

invalid_grant trying to get OpenID Connect token from PayPal

contemplator
Contributor
Contributor

I am following the Guide: Integrate Log In with PayPal in attempt to make it work on WordPress 4.7.1. I have successfully embed the Log In with PayPal button. Clicking on it bring the login, which then redirects to "returnurl".

 

I'm currently stuck trying to pass the authorization code received in the previous step to the tokenservice endpoint to receive an access token.

 

My "returnurl" has this curl code (as suggested by Guide: grant token from authorization code😞

<?php

$curl = curl_init( 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice' ); 
// not $curl = curl_init( 'https://api.sandbox.paypal.com/v1/oauth2/token' ); 
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$code = $_GET['code']; // The code from the previous request
$redirect_uri = 'http://xxxxxx.contemplate.me.ke/';

curl_setopt( $curl, CURLOPT_POSTFIELDS, array( 'redirect_uri' => $redirect_uri, 'grant_type' => 'authorization_code', 'code' => $code) );

curl_setopt( $curl, CURLOPT_USERPWD, "My-Client-Id" . ":" . "My-Secret");

$auth = curl_exec( $curl ); print '$auth = ';print_r($auth); // to see the error
$secret = json_decode($auth); $access_key = $secret->access_token; ?>

All I get from this after logging in is:

$auth = {"error_description":"Grant type is null","error":"invalid_grant","correlation_id":"0f5787fc6413f","information_link":"https://developer.paypal.com/docs/api/#errors"}

The API Documentation has no mention of this error, even though information_link is indicated.

 

What am I doing wrong?

Login to Me Too
Who Me Too'd this topic