允许 php 应用程序访问 /oauth2/authorize 端点 OPENAM

allow a php application to access to /oauth2/authorize endpoint OPENAM

我正在使用这个 php 脚本来访问 /oauth2/authorize openam 的端点:

<?php
    //debug
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    //debug end
    function get_web_page($url) 
    { 
        $options = array( 
        CURLOPT_RETURNTRANSFER => true,     // return web page 
        CURLOPT_HEADER         => true,    // return headers 
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects 
        CURLOPT_ENCODING       => "",       // handle all encodings 
        CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0", // who am i 
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect 
        ); 

        $ch      = curl_init($url); 
        curl_setopt_array($ch, $options); 
        $content = curl_exec($ch); 
        $header  = curl_getinfo($ch); 
        curl_close( $ch ); 
        //print($header[0]); 
        echo $content;
        //var_dump($content);
        return $header; 
    }  
    $thisurl = "http://openam.example.com:8080/openam/oauth2/authorize?realm=/openLDAP&client_id=agent2&redirect_uri=http://openam.test.com:8080/openam&response_type=code&scope=profile";`
    $myUrlInfo = get_web_page($thisurl); 
    //echo $myUrlInfo["url"];
?>

我得到的是空白网页,但我可以在副标题 "ForgeRock Access..." 中看到我认为 agent2 身份验证成功,因为当我将 "agent2" 更改为 "agent1" 我有这个调试文件夹中的错误:ERROR: Unable to get Client Registration for client_Id = agent1 这就是为什么我得出结论,我能够连接到端点,但我不明白为什么我没有被重定向到用户身份验证网页。 我已经尝试了相同的脚本并将 url 更改为“https://www.google.fr/”,在这种情况下我被重定向到 google。 预先感谢您的帮助。 添加 var_dump( $myUrlInfo ) 后的输出; :

array(26) { ["url"]=> string(35) "http://openam.test.com:8080/openam/" ["content_type"]=> string(9) "text/html" ["http_code"]=> int(200) ["header_size"]=> int(391) ["request_size"]=> int(498) ["filetime"]=> int(-1 ) ["ssl_verify_result"]=> 整数(0) ["redirect_count"]=> 整数(1) ["total_time"]=> 浮点数(0.007415) ["namelookup_time"]=> 浮点数(1.4E-5) ["connect_time"]=> 浮动(1.7E-5) ["pretransfer_time"]=> 浮动(9.4E-5) ["size_upload"]=> 浮动(0 ) ["size_download"]=> 浮动(1626) ["speed_download"]=> 浮动(219285) ["speed_upload"]=> 浮动(0) ["download_content_length"]=> 浮动(1626) ["upload_content_length"]=> 浮动(0) ["starttransfer_time"]=> 浮动(0.001315) ["redirect_time"]=> 浮动(0.006082) ["redirect_url"]= > 字符串(0) "" ["primary_ip"]=> 字符串(12) "XXX.XX.XX.XX" ["certinfo"]=> 数组(0) { } ["primary_port"]=> 整数(xx) ["local_ip"]=> 字符串(12) "XX.XX.XX.XX" ["local_port"]=> 整数(xxx) }

要重定向到 openam 的日志网页,我需要使用 header 方法。

<html>
        <head>
            <meta charset="utf-8"/>
            <link rel="stylesheet" href="style.css"/>   
            <title>UMA forgerock test appli</title>
        </head>

        <body>
            <h2 id="generateCode">Retrieve authorization code</h2>
                <form method="post" action="">
                    <input id="bouton" type="submit" name="generateCode" value="generateCode">
                </form>
            <?php
                if(isset($_POST['generateCode'])) {
                    $url = "http://openam.test.com:8080/openam/oauth2/authorize";
                    $params = array(
                        "response_type" => "code",
                        "client_id" => xxx,
                        "realm" => "/openLDAP",
                        "redirect_uri" => 'http://uma.test.com/umaTestAppli',
                        "scope" => "profile"
                    );

                    $request_to = $url . '?' . http_build_query($params);
                    header("Location: " . $request_to);
                }
            ?>
        </body>
    </html>