代码之家  ›  专栏  ›  技术社区  ›  Morteza Milani

如何使用OpenID身份验证检索配置文件数据?(Zend框架)

  •  0
  • Morteza Milani  · 技术社区  · 15 年前

    我阅读了一些教程,并想出了以下脚本来验证OpenID。但我不知道如何检索登录用户的配置文件数据,比如全名或电子邮件。有人能帮我吗?

    < PRE> >代码> $状态=‘’; $auth=zend_auth::getInstance(); $POR= = ARARY(); $get=$this->getRequest()->getParams(); 如果($this->getRequest()->ispost()){ $post=$this->getRequest()->getPost(); } $profile=new zend_openid_extension_sreg(数组( '昵称'=>正确, 'email'=>真, 'fullname'=>真),空,1.1 ; 如果($auth->hasIdentity()){ if(isset($get['openid\u action'])&$get['openid\u action']==“注销”)。{ $auth->clearIdentity(); $status=“已注销”; }否则{ $status=“以“.$auth->getIdentity()”身份登录; } }else if(isset($post['openid\u action'])&$post['openid\u action']='登录'&$post['openid\u identifier'])。{ $result=$auth->身份验证(new zend_auth_adapter_openid($post['openid_identifier']); $status='出了问题'; }else if(isset($get['openid_mode'])){ $result=$auth->身份验证(new zend_auth_adapter_openid()); 如果(!)$result->isvalid()){ $auth->clearIdentity(); } $status.=implode('
    ',$result->getmessages()); }否则{ $status='您没有登录'; } $this->查看->状态=$status; < /代码> <如果(!)$result->isvalid()){ $auth->clearIdentity(); } $status.=内爆('
    ',$result->getmessages()); }否则{ $status='您没有登录'; } $this->查看->状态=$status;
    1 回复  |  直到 10 年前
        1
  •  0
  •   Morteza Milani    15 年前

    好吧,我知道怎么做了:

    
    $status='';
    $auth=Zend_Auth::getInstance();
    $post=array();
    $get=$this->getRequest()->getParams();
    if($this->getRequest()->isPost()){
        $post=$this->getRequest()->getPost();
    }
    
    //changed nickname and fullname to false, so if provider didn't provide these, authentication won't fail.
    $profile=new Zend_OpenId_Extension_Sreg(array(
        'nickname' => false,
        'email'    => true,
        'fullname' => false),null,1.1
    );
    
    if($auth->hasIdentity()){
        if(isset($get['openid_action']) && $get['openid_action']=='logout'){
            $auth->clearIdentity();
            $status="logged Out";
        }else{
            $status="logged in as ".$auth->getIdentity();   
        }
    }else if(isset($post['openid_action']) && $post['openid_action']=='login' && $post['openid_identifier']){
        $result=$auth->authenticate(new Zend_Auth_Adapter_OpenId($post['openid_identifier'],null,null,null,$profile));
        $status='something went wrong';
    }else if(isset($get['openid_mode'])){
        $result=$auth->authenticate(new Zend_Auth_Adapter_OpenId(null,null,null,null,$profile));
        if(!$result->isValid()){
            $auth->clearIdentity();
        }else{
            //here you have the information you need.
            $info=$profile->getProperties();
        }
        $status.= implode('
    ',$result->getMessages());
    
    }else{
        $status='You are not logged in';
    }
    $this->view->status=$status;
    

    但是,如果你想使用谷歌、雅虎或任何OpenID2.0提供商,你应该 use patches .