1

Google を使用して StackOverflow にサインインすると、次のメッセージが表示されます。

Stackoverflow.com は、あなたの Google アカウント example@gmail.com からいくつかの情報を求めています

• メールアドレス: example@gmail.com

ただ、自分のサイトではOpenIDでログインするとメールアドレスを聞かれません。代わりに、次のメッセージが表示されます。

Google アカウント example@gmail.com で example.com にサインインしています

また、どのステップでメールアドレスを要求する必要があるのか​​ 理解するのが難しいと感じています. ステップを組み込む必要があると思われるコードは次のとおりです。

/**
 * Authenticates the given OpenId identity.
 * Defined by Zend_Auth_Adapter_Interface.
 *
 * @throws Zend_Auth_Adapter_Exception If answering the authentication query is impossible
 * @return Zend_Auth_Result
 */
public function authenticate() {
    $id = $this->_id;
    $consumer = new Auth_OpenID_Consumer($this->_storage);
    
    if (!empty($id)) {
        $authRequest = $consumer->begin($id);
        
        if (is_null($authRequest)) {
            return new Zend_Auth_Result(
                Zend_Auth_Result::FAILURE,
                $id,
                array("Authentication failed", 'Unknown error')
            );
        }
        
        if (Auth_OpenID::isFailure($authRequest)) {
            return new Zend_Auth_Result(
                Zend_Auth_Result::FAILURE,
                $id,
                array("Authentication failed", "Could not redirect to server: " . $authRequest->message)
            );
        }
        
        $redirectUrl = $authRequest->redirectUrl($this->_root, $this->_returnTo);
        
        if (Auth_OpenID::isFailure($redirectUrl)) {
            return new Zend_Auth_Result(
                Zend_Auth_Result::FAILURE,
                $id,
                array("Authentication failed", $redirectUrl->message)
            );
        }
        
        Zend_OpenId::redirect($redirectUrl);
    } else {
        $response = $consumer->complete(Zend_OpenId::selfUrl());

        switch($response->status) {
            case Auth_OpenID_CANCEL:
            case Auth_OpenID_FAILURE:
                return new Zend_Auth_Result(
                    Zend_Auth_Result::FAILURE,
                    null,
                    array("Authentication failed. " . @$response->message)
                );
                break;
            case Auth_OpenID_SUCCESS:
                return $this->_constructSuccessfulResult($response);
                break;
        }
    }
}

これはとても明白なように思えます...しかし、私はそれをグーグルで検索し、コードをくまなく調べて理解するのに苦労しています。どんな助けでも大歓迎です!

4

1 に答える 1

1

Zend Simple Registration Extensionを使用してメールアドレスを要求できます

$sreg = new Zend_OpenId_Extension_Sreg(array(
    'nickname'=>true,
    'email'=>false,
    'fullname'=>false), null, 1.1);
$consumer = new Zend_OpenId_Consumer();
if (!$consumer->login($_POST['openid_identifier'],
                      'example-6_3.php',
                      null,
                      $sreg)) {
    die("OpenID login failed.");
}

Janrain ライブラリを使用する場合は、次のようにリクエストに拡張機能を追加できます。

$sreg_request = Auth_OpenID_SRegRequest::build(
                                 // Required
                                 array('nickname'),
                                 // Optional
                                 array('email'));

if ($sreg_request) {
    $authRequest->addExtension($sreg_request);
}

コンシューマーの例をご覧ください: https://github.com/openid/php-openid/blob/master/examples/consumer/

于 2011-09-09T15:54:19.103 に答える