6

I have added simpleopenidselector and lightopenid to my Yii web app and it does authenticate the user and it returns a url with openid data. The next step is to use the data from the OpenID provider to create a new identity in Yii to log in the user. How is this done with Yii?

Also, I think I need to create an openid table in order to store the openid's and also need to add the user to my user table. If the user has an account already then add the openid to their user account to prevent multiple accounts.

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

Mark
  • 647
  • 2
  • 9
  • 27
  • I haven't used it myself, but I wonder if it's possible to integrate this with the [yii-user](http://www.yiiframework.com/extension/yii-user/) extension? – ldg Aug 12 '11 at 17:12
  • @ldg - [yii-user-management](http://www.yiiframework.com/extension/yii-user-management/) has openid included with it but I don't need the entire user management, and I can't follow the code enough to see how they implemented the openid login part. I just started coding in the OOP style, so that's making it tough too. I did not see the openid in the yii-user link you mentioned. – Mark Aug 16 '11 at 02:46

1 Answers1

1

To use the data from openID as Yii login, you could modify/overwrite the UserIdentity Class (protected/components).

Overwrite the existing authenticate method. At this point you also can set the current Yii username, like:

$this->username=$openId->username

(where $openId->username should be replaced by the variable which contains the openID user name)

By overwriting the side/login action, you can call your modified method, like this:

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

//Update (because of your comment): Not sure, if I understand your problem right. But what's about adding a new method in UserIdentity, like authenticateOID(). call this method at the beginning of the original authenticate() method, like so:

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 done and/or if the user still in you local "OID - user table"

The Bndr
  • 13,204
  • 16
  • 68
  • 107
  • I would rather not overwrite or change the current authentication since I need to login registered users and openid users. I have tried to modify the UserIdentity but always run into issues with needing the username and password, when I only have a username from openid. I need to check if the openid user is a registered user as well by checking the username against my users table. Sorry if that doesn't make sense ...I'm new to Yii and OOP. – Mark Aug 16 '11 at 20:21
  • The authentcation part is OK, it's the new UserIdentity part that I cannot seem to workout. After the OpenID login is authenticated, I don't need to authenticate it again, at least that's what I was thinking. After the user is authenticated via OpenID, I would like to create a new UserIdentity, but the current Yii user login method requires the user password when logging in and OpenID does not which is the issue I can't seem to get through. – Mark Aug 19 '11 at 02:31
  • I'm using LDAP SSO at my Yii application, which is similar to your issue. During the authenticate method, i simply set `$this->username` to the authenticated user/unique userID. So `Yii::app()->user->login($identity)` works fine, without changes and without any new login/password from Yii – The Bndr Aug 19 '11 at 07:51