Question

I have an issue that i can't resolve. I'm trying to create an application on wordpress wherein when a user visits a page it will automatically ask the user to login and authenticate using a paypal account. When successfully log-in, I wanted to display the profile details(first for testing only) and later code it again for the intended use. However, I use the code below, and when I successfully logged, authenticate and get redirected to the redirect_url(meaning the process in logging in and authentication is done correctly) the expected profile details via print_r is empty.

<?php
/* Paypal app details */
$client_id = 'xxxx';    // paypal client id
$client_secret = 'xxx'; // client secret
$scopes = 'email profile';  //e.g. openid email profile https://uri.paypal.com/services/paypalattributes
$app_return_url = 'http://website.ccc/verify/';  // Redirect url
$nonce = time() . rand();

$code = $_REQUEST["code"];

if(empty($code)) {
    #IF the code paramater is not available, load the auth url.
    $state = md5(uniqid(rand(), TRUE)); // CSRF protection
    $paypal_auth_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?"
            ."client_id=".$client_id
            ."&response_type=code"
            ."&scope=".$scopes
            ."&nonce=".$nonce
            ."&state=".$state
            ."&redirect_uri=".urlencode($app_return_url);

    header("Location: $paypal_auth_url");     
}else{
    /* GET Access TOKEN */
    $token_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice";    
    $postvals = "client_id=".$client_id
            ."&client_secret=".$client_secret
            ."&grant_type=authorization_code"
            ."&code=".$code;


    $ch = curl_init($token_url);
    $options = array(
                CURLOPT_POST => 1,
                CURLOPT_VERBOSE => 1,
                CURLOPT_POSTFIELDS => $postvals,
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_SSLVERSION => 3
    );
    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch);
    curl_close($ch);
    $atoken = json_decode($response);

    /* GET PROFILE DETAILS */
    $profile_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?"
            ."schema=openid"
            ."access_token=".$atoken->access_token;

    $ch = curl_init($profile_url);
    $options = array(
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_SSLVERSION => 3
    );
    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch);
    curl_close($ch);
    $profile= json_decode($response,true);  // PROFILE DETAILs in Array format


    /* View the Profile Details */

    echo "<pre>";
    print_r($profile);
    echo "</pre>";
}

?>

Can you help me dig with this?

No correct solution

OTHER TIPS

Hi friend simply add '&' on before access token,

$profile_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?" ."schema=openid" ."**&**access_token=".$atoken->access_token;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top