2012-01-02 1 views
2

로그인 시스템으로 openid를 사용하려고합니다. 그 때문에 나는 다음 코드를 사용했다.

<?php 
require 'openid.php'; 

try { 
if(!isset($_GET['openid_mode'])) 
{ 
    if(isset($_GET['login'])) 
    { 
     $openid = new LightOpenID; 
     $openid->identity = 'https://www.google.com/accounts/o8/id'; 
     $openid->required = array('contact/email'); 
     header('Location: ' . $openid->authUrl()); 
    } 
?> 

<form action="?login" method="post"> 
<button>Login with Google</button> 
</form> 

<?php 
} 
elseif($_GET['openid_mode'] == 'cancel') 
{ 
    echo 'User has canceled authentication!'; 
} 
else 
{ 
    $openid = new LightOpenID; 
    echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.'; 
} 
} catch(ErrorException $e) { 
echo $e->getMessage(); 
} 
?> 

그러나 나는 코드에 문제가있다. $ openid-> validate가이 코드에서하는 것. 나는 인터넷에서 검색하지만 그것에 대한 정보를 얻지 못했습니다. 사전에

감사합니다 ....

답변

0

$openid->validate()은 인수가없는 및 ​​부울을 반환합니다.

해당 정의는 openid.php에 있어야합니다.

직관적으로 말하면 사용자 이름과 암호의 유효성을 검사합니다 (유효한 사용자를 인증 함).

+0

답장을 보내 주셔서 감사합니다. 하지만 나는 $ openid-> validate()가 사용자가 로그인하지 않아도 true를 반환하는 것처럼 사용자 이름과 암호의 유효성을 검사한다고 생각하지 않습니다. – user392406

+0

@ user392406 - 다른 브라우저 탭에서 OpenID 제공 업체의 페이지를 열고 ** 로그 아웃하면 ** 여전히 TRUE를 반환합니까? –

1

편집 : validate() 기능 전에 $openid = new LightOpenID; 줄을 삭제하십시오. https://gitorious.org/lightopenid/lightopenid/blobs/master/example.php


난 당신이 openid.php보고 유효성 검사() 함수를 확인해야합니다 추측이 예를 확인 . OP로 OpenID 확인을 수행합니다.

/** 
* Performs OpenID verification with the OP. 
* @return Bool Whether the verification was successful. 
* @throws ErrorException 
*/ 
function validate() 
{ 
    # If the request was using immediate mode, a failure may be reported 
    # by presenting user_setup_url (for 1.1) or reporting 
    # mode 'setup_needed' (for 2.0). Also catching all modes other than 
    # id_res, in order to avoid throwing errors. 
    if(isset($this->data['openid_user_setup_url'])) { 
     $this->setup_url = $this->data['openid_user_setup_url']; 
     return false; 
    } 
    if($this->mode != 'id_res') { 
     return false; 
    } 

    $this->claimed_id = isset($this->data['openid_claimed_id'])?$this->data['openid_claimed_id']:$this->data['openid_identity']; 
    $params = array(
     'openid.assoc_handle' => $this->data['openid_assoc_handle'], 
     'openid.signed'  => $this->data['openid_signed'], 
     'openid.sig'   => $this->data['openid_sig'], 
     ); 

    if (isset($this->data['openid_ns'])) { 
     # We're dealing with an OpenID 2.0 server, so let's set an ns 
     # Even though we should know location of the endpoint, 
     # we still need to verify it by discovery, so $server is not set here 
     $params['openid.ns'] = 'http://specs.openid.net/auth/2.0'; 
    } elseif (isset($this->data['openid_claimed_id']) 
     && $this->data['openid_claimed_id'] != $this->data['openid_identity'] 
    ) { 
     # If it's an OpenID 1 provider, and we've got claimed_id, 
     # we have to append it to the returnUrl, like authUrl_v1 does. 
     $this->returnUrl .= (strpos($this->returnUrl, '?') ? '&' : '?') 
         . 'openid.claimed_id=' . $this->claimed_id; 
    } 

    if ($this->data['openid_return_to'] != $this->returnUrl) { 
     # The return_to url must match the url of current request. 
     # I'm assuing that noone will set the returnUrl to something that doesn't make sense. 
     return false; 
    } 

    $server = $this->discover($this->claimed_id); 

    foreach (explode(',', $this->data['openid_signed']) as $item) { 
     # Checking whether magic_quotes_gpc is turned on, because 
     # the function may fail if it is. For example, when fetching 
     # AX namePerson, it might containg an apostrophe, which will be escaped. 
     # In such case, validation would fail, since we'd send different data than OP 
     # wants to verify. stripslashes() should solve that problem, but we can't 
     # use it when magic_quotes is off. 
     $value = $this->data['openid_' . str_replace('.','_',$item)]; 
     $params['openid.' . $item] = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ? stripslashes($value) : $value; 
    } 

    $params['openid.mode'] = 'check_authentication'; 

    $response = $this->request($server, 'POST', $params); 

    return preg_match('/is_valid\s*:\s*true/i', $response); 
}