Traducir comandos cURL a PHP cURL (SSL)

corrí

este rizo en la línea de comando en mi Terminal

curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=e1968018-bb04-4475-86fa-b0728e9fb038&nonce=f7b76b29-2c42-423d-8d1c-5b1d0a8ce8bf&response_type=code&claims=%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D" 2>/dev/null| curl -v -b session_cookies.txt -L -H "Content-Type: application/x-www-form-urlencoded" -v -d '[email protected]&j_password=123' "https://login.uat.site.be/openid/login.do" 2>&1 >/dev/null | grep Location | grep code=

tengo

esta respuesta de vuelta

< Location: https://testserver.sitenets.com/user/secure/dashboard?code=4z71kBZ4iYlqfDB7qOHvZgyXkqVEaL7v&state=e1968018-bb04-4475-86fa-b0728e9fb038

Nota

code=4z71kBZ4iYlqfDB7qOHvZgyXkqVEaL7v

Eso es lo que busco.

Entonces

He intentado convertir mis líneas de comando de curl a PHP curl

  $ch = curl_init( 'https://login.uat.site.be/openid/oauth/authorize' );
  curl_setopt($ch, CURLOPT_POST, true );
  curl_setopt($ch, CURLOPT_POSTFIELDS, array(

    'client_id' => 'site',
    'state' => $state,
    'nonce' => $nonce,
    'claims' => '%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D',
    'response_type' => 'code'

    ) );

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_COOKIEJAR, public_path().'/session_cookies.txt');
  curl_setopt($ch, CURLOPT_VERBOSE, true);

  $first_curl = curl_exec($ch);

  $cookie_file = public_path(). '/session_cookies.txt';
  if (file_exists($cookie_file)) {

    $pem_file_path = '/Applications/MAMP/conf/apache/openid.site.com.cert.pem';

    $options = array(
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_SSL_VERIFYPEER => true,
      CURLOPT_CAINFO=> $pem_file_path,
      CURLOPT_POST => true,
      CURLOPT_POSTFIELDS => http_build_query(array(
        'j_username' => urlencode($un),
        'j_password' => $pw,
        )),
      CURLOPT_COOKIEJAR => $cookie_file,
      CURLOPT_COOKIEFILE => $cookie_file,
      );
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    curl_setopt($ch, CURLOPT_URL, 'https://login.uat.site.be/openid/login.do');
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
      echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);

    dd($result);
  }

Nunca obtengo el mismo resultado que habría ejecutado ese comando en mi Terminal.

Sigo recibiendo esta basura en mi navegador, cuandodd fuera mi$result variable

   """
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->\r\n
    <!DOCTYPE html>\r\n
    <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->\r\n
    <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->\r\n
    <!--[if gt IE 8]><!-->\r\n
    <html class="no-js">\r\n
    <!--<![endif]-->\r\n
    <head>\r\n
        <title>site: Meld je aan</title>\r\n
        <meta content="IE=edge" http-equiv="X-UA-Compatible">\r\n
        <meta charset="utf-8">\r\n
        <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">\r\n
        <meta name="description" content="">\r\n
    \r\n
        <link rel="shortcut icon" href="//static.site.be/assets/favicon/favicon.ico" type="image/x-icon"/>\r\n
        <link rel="stylesheet" href="css/vendor/normalize.min.css">\r\n
        <link rel="stylesheet" href="css/login.css">\r\n
        <link rel="stylesheet" type="text/css" href="//static.site.be/assets/fonts/omnes-breuer-logo/stylesheet.css">\r\n
        \r\n
        <link rel="stylesheet" href="https://static.uat.site.be/oauth2/css/main.css">\r\n
    \r\n
        <!-- Adobe analytics -->\r\n
        <script src="https://www2.site.be/etc/designs/site-be/js/statistics/SiteCatalyst.js"></script>\r\n
    \r\n
        <script type="text/javascript">\r\n
            function hideHtmlElement(id) {\r\n
                document.getElementById(id).style.display = "none";\r\n
            }\r\n
    \r\n
            function showHtmlElement(id) {\r\n
                document.getElementById(id).style.display = "block";\r\n
            }\r\n
    \r\n
            function showPanel(id) {\r\n
                hideHtmlElement("forgotLogin");\r\n
                hideHtmlElement("showLogin");\r\n
                hideHtmlElement("forgotPassword");\r\n
                showHtmlElement(id);\r\n
            }\r\n
    \r\n
        </script>\r\n
    \r\n
        <!--[if lt IE 9]>\r\n
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>\r\n
        <![endif]-->\r\n
    </head>\r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    <div class="wrapper">\r\n
        <span id="showBackgroundForStatic" style="display: none">true</span>\r\n
        <!-- ERROR SCREEN -->\r\n
        <div class="container">\r\n
            <div id="loginContainer">\r\n
                <div id="showLogin">\r\n
                    <div class="options clearfix">\r\n
                        <div class="option-sites">\r\n
                            <ul>\r\n
                                <li><a target="_blank"\r\n
                                       href="http://site.be/nl">Meer site</a></li>\r\n
                                <li><a target="_blank" href="http://site.be/nl"\r\n
                                       tabindex="-1">site.be</a></li>\r\n
                                <li><a target="_blank" href="http://business.site.be/"\r\n
                                       tabindex="-1">Business</a></li>\r\n
                                <li><a target="_blank"\r\n
                                       href="http://corporate.site.be/" tabindex="-1">Over site</a></li>\r\n
                                <li><a target="_blank"\r\n
                                       href="http://klantenservice.site.be/"\r\n
                                       tabindex="-1">Klantenservice</a></li>\r\n
                            </ul>\r\n
                        </div>\r\n
                        <div class="option-language">\r\n
                            <ul>\r\n
                                <span id="languageForStatic" style="display: none">nl</span>\r\n
                                <!-- IT-4522 The design team uses languageForStatic to display text dynamically-->\r\n
                                \r\n
                                    \r\n
                                        <li class="active"><a href="?lang=nl" tabindex="-1">NL</a></li>\r\n
                                        <li><a href="?lang=fr" tabindex="-1">FR</a></li>\r\n
                                    \r\n
                                    \r\n
                                \r\n
                            </ul>\r\n
                        </div>\r\n
                    </div>\r\n
    \r\n
                    <div class="branding clearfix">\r\n
                        <div id="logo"><img src="https://static.site.be/oauth2/images/logosite.png"\r\n
                                            data-at2x="https://static.site.be/oauth2/images/[email protected]"\r\n
                                            alt="site"></div>\r\n
                        <h1><label>Fout bij aanmelden</label></h1>\r\n
                        <span id="languageForStatic" style="display: none">nl</span>\r\n
                        <!-- IT-5252 The design team uses languageForStatic to display text dynamically-->\r\n
                    </div>\r\n
                    <div class="contentContainer">\r\n
                        <p>Er ging iets mis. Gelieve de applicatie af te sluiten en daarna opnieuw op te starten.</p>\r\n
                    </div>\r\n
                </div>\r\n
    \r\n
    \r\n
            </div>\r\n
            <div class="copyright">&copy; site\r\n
                <script>document.write(new Date().getFullYear());</script>\r\n
                - <a href="http://klantenservice.site.be/content/juridische-informatie" target="_blank"\r\n
                     tabindex="-1">Juridische informatie</a>\r\n
                - <a href="https://www2.site.be/nl/privacy/"\r\n
                     href="https://www2.site.be/nl/privacy/" target="_blank"\r\n
                     tabindex="-1">Privacy</a><br>\r\n
                <a href="http://klantenservice.site.be/content/waar-vind-ik-de-algemene-voorwaarden-van-site" target="_blank"\r\n
                   tabindex="-1">Tariefinfo en algemene voorwaarden</a>\r\n
            </div>\r\n
        </div>\r\n
        <div class="bgContainer"></div>\r\n
    </div>\r\n
    \r\n
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>\r\n
    <script src="/openid/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>\r\n
    <script src="/openid/js/vendor/retina-1.1.0.min.js"></script>\r\n
    \r\n
    <!--[if lt IE 9]>!\r\n
    <script type="text/javascript" src="/openid/js/vendor/jquery.backgroundSize.js"></script>!\r\n
    <![endif]-->\r\n
    \r\n
    <script src="https://static.uat.site.be/oauth2/js/items.js"></script>\r\n
    <script src="https://static.uat.site.be/oauth2/js/main.js"></script>\r\n
    \r\n
    </body>\r\n
</html>\r\n
"""

Ahora estoy atrapado, no estoy seguro de qué hice mal, no estoy seguro de qué hacer a continuación.

Preguntas

¿Cómo puedo convertir mi rizo para obtener el mismo resultado?

¿Es algo que necesito habilitar en mi configuración de curl PHP?

¿Es algo que necesito actualizar en mi configuración de Apache?

¿Qué hay de malo con mis PHP CURLs?

¿Cómo se podría proceder y depurar esto más?

Respuestas a la pregunta(1)

Su respuesta a la pregunta