2012-11-20 40 views
0

首先,我首先介紹一下這個事實,即我對OpenID完全陌生,對PHP不太熟悉。爲什麼Janrain的Engage示例只能在IE中工作?

我設置Janrain的搞例如在我的網站(Apache的/ PHP),包括他們在頭部分的JavaScript:

(function() { 

    if (typeof window.janrain !== 'object') { 
     window.janrain = {}; 
    } 
    if (typeof window.janrain.settings !== 'object') { 
     window.janrain.settings = {}; 
    } 

    janrain.settings.tokenUrl = 'http://mydomain.com/tokenform.php'; 

    function isReady() { 
     janrain.ready = true; 
    }; 

    if (document.addEventListener) { 
     document.addEventListener("DOMContentLoaded", isReady, false); 
    } else { 
     window.attachEvent('onload', isReady); 
    } 

    var e = document.createElement('script'); 
    e.type = 'text/javascript'; 
    e.id = 'janrainAuthWidget'; 

    if (document.location.protocol === 'https:') { 
     e.src = 'https://rpxnow.com/js/lib/myapp/engage.js'; 
    } else { 
     e.src = 'http://widget-cdn.rpxnow.com/js/lib/myapp/engage.js'; 
    } 

    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(e, s); 

})(); 

我加入他們的DIV標籤:

<div id="janrainEngageEmbed"></div> 

我建基於他們的指令的以下令牌收據頁面:

<?php 

header('Content-Type: text/html; charset=utf-8'); 

?> 
<html> 
    <head> 
     <title>Janrain Engage example</title> 
    </head> 
    <body> 
     <pre> 
<?php 

$rpx_api_key = file_get_contents('/path/apikey.txt'); 

/* STEP 1: Extract token POST parameter */ 
$token = $_POST['token']; 

echo "SERVER VARIABLES:\n"; 
var_dump($_SERVER); 
echo "HTTP POST ARRAY:\n"; 
var_dump($_POST); 

// test the length of the token; it should be 40 characters 
if (strlen($token) == 40) { 

    /* STEP 2: Use the token to make the auth_info API call */ 
    $post_data = array('token' => $token, 
        'apiKey' => $rpx_api_key, 
        'format' => 'json', 
        'extended' => 'false'); 

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_URL, 'https://rpxnow.com/api/v2/auth_info'); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_FAILONERROR, true); 
    $result = curl_exec($curl); 
    if ($result == false){ 
     echo "\n".'Curl error: ' . curl_error($curl); 
     echo "\n".'HTTP code: ' . curl_errno($curl); 
     echo "\n"; var_dump($post_data); 
    } 
    curl_close($curl); 

    /* STEP 3: Parse the JSON auth_info response */ 
    $auth_info = json_decode($result, true); 

    if ($auth_info['stat'] == 'ok') { 

     echo "\n You're in!"; 
     echo "\n auth_info:"; 
     echo "\n"; var_dump($auth_info); 

     /* STEP 4: Use the identifier as the unique key to sign the user into your system. 
     This will depend on your website implementation, and you should add your own 
     code here. The user profile is in $auth_info. 
     */ 

    } else { 
     // Gracefully handle auth_info error. Hook this into your native error handling system. 
     echo "\n".'An error occured: ' . $auth_info['err']['msg']."\n"; 
     var_dump($auth_info); 
     echo "\n"; 
     var_dump($result); 
    } 
} else { 
    // Gracefully handle the missing or malformed token. Hook this into your native error handling system. 
    echo 'Authentication canceled.'; 
} 

?> 
     </pre> 
    </body> 
</html> 

我的小工具接受登錄來自谷歌,Facebook,Twitter,雅虎,LinkedIn和Windows Live。只要我使用IE,一切都可以像廣告一樣工作。如果我嘗試使用Firefox或Chrome的任何提供商,我似乎已通過身份驗證,登錄對話框消失了,但我使用Open ID提供程序選擇窗口小部件卡在了頁面上。

任何想法?

回答

2

事實證明,Janrain似乎依靠第三方cookie來使其機制發揮作用。雖然它可能在某個地方被記錄下來,但是在經過幾個小時的尋找之後,我沒有發現它。

在Firefox中,工具,選項,隱私和檢查第三方cookie允許Janrain示例開始工作。

在Chrome中,程序是:chrome:// chrome/settings /,顯示高級設置,內容設置,取消選中「阻止第三方Cookie和網站數據」。

Janrain示例繼續在IE9中工作,不管Block第三方Cookie設置如何。我在iOS上擁有與Safari相同的經驗。 (它只接受來自訪問網站的cookies。)

相關問題