2010-06-02 76 views

回答

0

Google的OpenID(Google Apps for Domains OpenID除外)只是標準的OpenID。您應該採取其他任何OpenID所需的所有預防措施,以確保斷言是合法的。你是對的......任何人都可以編寫一個OpenID肯定的斷言來欺騙你的RP,除非你的RP驗證了簽名,在標識符上執行發現並將該標識符的授權OP端點與簽名響應的標識符進行匹配。

至於你是否可以信任電子郵件地址,這取決於你。您可以選擇信任Google OP終端,然後您知道。

-1
function ValidateWithServer(){ 
    $params = array(
     'openid.assoc_handle' => urlencode($_REQUEST['openid_assoc_handle']), 
     'openid.signed' => urlencode($_REQUEST['openid_signed']), 
     'openid.sig' => urlencode($_REQUEST['openid_sig']) 
    ); 
    // Send only required parameters to confirm validity 
    $arr_signed = explode(",",str_replace('sreg.','sreg_',$_REQUEST['openid_signed'])); 
    for ($i=0; $i<count($arr_signed); $i++){ 
     $s = str_replace('sreg_','sreg.', $arr_signed[$i]); 
     $c = $_REQUEST['openid_' . $arr_signed[$i]]; 
     // if ($c != ""){ 
      $params['openid.' . $s] = urlencode($c); 
     // } 
    } 
    $params['openid.mode'] = "check_authentication"; 

    $openid_server = $this->GetOpenIDServer(); 
    if ($openid_server == false){ 
     return false; 
    } 
    $response = $this->CURL_Request($openid_server,'POST',$params); 
    $data = $this->splitResponse($response); 

    if ($data['is_valid'] == "true") { 
     return true; 
    }else{ 
     return false; 
    } 
} 
+0

您不應該依賴$ _GET,因爲響應數據可能在$ _POST中。 – AlBeebe 2011-03-14 13:49:48

1
public function verify_response() 
     {$params=$_REQUEST; 
     $query=array('openid.signed'=>$params['openid.signed'], 
        'openid.sig'=>$params['openid.sig'], 
        'openid.mode'=>'check_authentication' 
        ); 
     $keys=explode(',', 'openid.'.strtr($params['openid.signed'], array(','=>',openid.'))); 
     foreach ($params as $k=>$v) 
       {if (in_array($k, $keys)) 
        {$query[$k]=$v; 
        } 
       } 
     $query=http_build_query($query); 
     $response=file_get_contents($params['openid.op_endpoint'].'?'.$query); 
     return stripos($response, 'is_valid:true')!==false; 
     }