How do I log in with Yii and OpenID

I added simpleopenidselector and lightopenid to my Yii web application, and it authenticates the user and returns a URL with open data. The next step is to use the data from the OpenID provider to create a new identifier in Yii for user login. How is this done with Yii?

Also, it seems to me that I need to create an openid table in order to keep openid as well as add a user to my user table. If the user already has an account, add openid to your account to prevent multiple accounts.

Has anyone achieved all this with Yii? If so, I would be very interested in how this was done.

+6
source share
1 answer

To use data from openID as a Yii login, you can change / overwrite the UserIdentity class (protected / components).

Overwrite existing authentication method. At this point, you can also set the current username Yii, for example:

$this->username=$openId->username 

(where $openId->username should be replaced with a variable that contains the openID username)

By rewriting the side / login action, you can call your modified method, for example:

 $identity=new UserIdentity("m","m");//where m is dummy if($identity->authenticate()) { Yii::app()->user->login($identity); [...] } 

// Update (due to your comment): Not sure if I understand your problem correctly. But what about adding a new method to UserIdentity, like authenticateOID (). call this method at the beginning of the original authenticate () method, for example:

 if ($this->authenticateOID) {/*set username & return true to end the method here*/} else {/*original authenticate method from Yii*/} 

Inside authenticateOID() you check if OID authentication is being performed and / or if the user is still in your local "OID-user" table

+1
source

Source: https://habr.com/ru/post/894923/


All Articles