Gigya Job Openings

Page History

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$clientID = "<The RP client_id>";
$clientSecret = "<The RP client_secret>";
$apiKey = "<The OP API key>";
$refreshToken;
$errors = null"";

if (isset($_POST['refreshToken']) && $_POST['refreshToken'] !== "") {
    $refreshToken = $_POST['refreshToken'];
} else {
    $refreshToken = null;
    $errors .='refreshToken was undefined. ';
}

// Try to refresh
function tryRefresh($inc_token,$id,$sec,$api) {
    $authHeader="Basic ";
    $client_ID = $id;
    $secret= $sec;
    $hashedAuthString=base64_encode($client_ID . ":" . $secret);
    $authHeader .= $hashedAuthString;

    $fields = array(
        'refresh_token'=>$inc_token,
        'grant_type'=>'refresh_token'
    );
    $postvars='';
    $sep='';
    foreach($fields as $key=>$value)
    {
        $postvars.= $sep.urlencode($key).'='.urlencode($value);
        $sep='&';
    }

    $ch = curl_init();
    $urlrefresh = "https://fidm.us1.gigya.com/oidc/op/v1.0/" . $api . "/token";
    curl_setopt($ch,CURLOPT_URL,$urlrefresh);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: ' . $authHeader));
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $curlResultRefresh = curl_exec($ch);
    curl_close($ch);
    echo '"response":' . $curlResultRefresh;
}
if ($refreshToken) {
    tryRefresh($refreshToken,$clientID,$clientSecret,$apiKey);
} else {
    echo '"response":{ "error" : "invalid or missing required parameter", "message" : "' . $errors . '" }';
}

?>

...