Hybridauth:如何在yii框架中验证twitter用户


hybridauth : how to authenticate twitter user in yii framework

我正在遵循http://www.yiiframework.com/wiki/459/integrating-hybridauth-directly-into-yii-without-an-extension/

的教程。

我包含了twitter登录,

问题是twitter没有返回电子邮件地址

Hybrid_User_Profile Object ([identifier] => 2378654169 [webSiteURL])=> https://tisthedomainname.co/tpAnZH2BGe [profileURL] => http://twitter.com/myhjghj [photoURL] =>http://pbs.twimg.com/profile_images/639065265478965088/8zty_o1K.png[displayName] => myhjghj [description] =>一些文本在这里-https://tisthedomainname.co/0yuxRheYVD [firstName] => myhjghj [lastName] => [gender]=>[语言]=>[时代]=>[生日]=> [birthMonth] => [birthYear] =>[电子邮件]=> [emailVerified] =>[电话]=>[地址]=>[中国]=>(地区)=>英国(城市)=> [zip] =>)

,并在此url https://dev.twitter.com/rest/reference/get/account/verify_credentials(并告诉我如何使用这个url以及何时使用)上面提到

"如果用户的帐户上没有电子邮件地址,或者电子邮件地址未经验证,则返回null。"

为facebook和google我使用电子邮件地址登录

public function login()
{
    $this->username = $this->userProfile->email;  //CUserIdentity
    Yii::app()->user->login($this, 0);
}

那么,如果用户在twitter中没有电子邮件id,我如何登录用户?

您可以查看现有验证机制的源代码,并从中获取方法。

例如:https://github.com/SleepWalker/hoauth。他是这样解释他的方法的:

当你计划使用像Twitter这样的社交网络时,返回no你应该声明verifyPassword($password)或用户模型中的validatePassword($password)方法,应该采取密码(不是散列),如果有效则返回true。

你也可以声明sendActivationMail()方法,它应该标记用户帐户处于非活动状态,并发送邮件进行激活。这方法,当它存在时将用于社交网络,如Twitter,它没有给我们用户的电子邮件数据(因为我们需要)证明用户输入了正确的电子邮件)。