public static function createFromAuthorizationCode($params, $clientId, $clientSecret, $apiContext = null)
{
static $allowedParams = array('grant_type' => 1, 'code' => 1, 'redirect_uri' => 1);
if (is_null($apiContext)) {
$apiContext = new PPApiContext();
}
$config = $apiContext->getConfig();
if ($apiContext->get($clientId) !== false) {
$clientId = $apiContext->get($clientId);
}
if ($apiContext->get($clientSecret) !== false) {
$clientSecret = $apiContext->get($clientSecret);
}
if (!array_key_exists('grant_type', $params)) {
$params['grant_type'] = 'authorization_code';
}
$call = new PPRestCall($apiContext);
$token = new PPOpenIdTokeninfo();
$token->fromJson($call->execute(array(new PPOpenIdHandler()), "/v1/identity/openidconnect/tokenservice", "POST", http_build_query(array_intersect_key($params, $allowedParams)), array('Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => 'Basic ' . base64_encode($clientId . ":" . $clientSecret))));
return $token;
}