public complete ( string $current_url, array $query = null ) : Auth_OpenID_ConsumerResponse | ||
$current_url | string | The URL used to invoke the application. Extract the URL from your application's web request framework and specify it here to have it checked against the openid.current_url value in the response. If the current_url URL check fails, the status of the completion will be FAILURE. |
$query | array | An array of the query parameters (key => value pairs) for this HTTP request. Defaults to null. If null, the GET or POST data are automatically gotten from the PHP environment. It is only useful to override $query for testing. |
리턴 | Auth_OpenID_ConsumerResponse | $response A instance of an Auth_OpenID_ConsumerResponse subclass. The type of response is indicated by the status attribute, which will be one of SUCCESS, CANCEL, FAILURE, or SETUP_NEEDED. |
function complete($current_url, $query = null)
{
if ($current_url && !is_string($current_url)) {
// This is ugly, but we need to complain loudly when
// someone uses the API incorrectly.
trigger_error("current_url must be a string; see NEWS file " . "for upgrading notes.", E_USER_ERROR);
}
if ($query === null) {
$query = Auth_OpenID::getQuery();
}
$loader = new Auth_OpenID_ServiceEndpointLoader();
$endpoint_data = $this->session->get($this->_token_key);
$endpoint = $loader->fromSession($endpoint_data);
$message = Auth_OpenID_Message::fromPostArgs($query);
$response = $this->consumer->complete($message, $endpoint, $current_url);
$this->session->del($this->_token_key);
if (in_array($response->status, array(Auth_OpenID_SUCCESS, Auth_OpenID_CANCEL))) {
if ($response->identity_url !== null) {
$disco = $this->getDiscoveryObject($this->session, $response->identity_url, $this->session_key_prefix);
$disco->cleanup(true);
}
}
return $response;
}
function openid_verify() { $consumer = new Auth_OpenID_Consumer(new Auth_OpenID_MySQLStore(theDb())); // Complete the authentication process using the server's // response. $return_to = getReturnTo(); $response = $consumer->complete($return_to); // Check the response status. if ($response->status == Auth_OpenID_CANCEL) { // This means the authentication was cancelled. $msg = 'Verification cancelled.'; } else { if ($response->status == Auth_OpenID_FAILURE) { // Authentication failed; display the error message. $msg = "OpenID authentication failed: " . $response->message; } else { if ($response->status == Auth_OpenID_SUCCESS) { // This means the authentication succeeded; extract the // identity URL and Simple Registration data (if it was // returned). $openid = $response->getDisplayIdentifier(); $esc_identity = htmlentities($openid); $success = sprintf('You have successfully verified ' . '<a href="%s">%s</a> as your identity.', $esc_identity, $esc_identity); if ($response->endpoint->canonicalID) { $escaped_canonicalID = htmlentities($response->endpoint->canonicalID); $success .= ' (XRI CanonicalID: ' . $escaped_canonicalID . ') '; } $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); $sreg = $sreg_resp->contents(); $ax = new Auth_OpenID_AX_FetchResponse(); $obj = $ax->fromSuccessResponse($response); if ($obj) { function ax_get($obj, $url) { if (!$obj) { return ""; } $x = $obj->get($url); if (is_array($x) && is_string($x[0])) { return $x[0]; } return ""; } if ($x = ax_get($obj, 'http://axschema.org/contact/email')) { $sreg["email"] = $x; } if ($x = ax_get($obj, 'http://axschema.org/namePerson/first')) { $sreg["fullname"] = $x . " " . ax_get($obj, 'http://axschema.org/namePerson/last'); } } openid_user_update($openid, $sreg); unset($_SESSION["auth_error"]); return true; } } } $_SESSION["auth_error"] = $msg; return false; }