This wrapper class allows to use lightopenid as a component in Yii framework applications. The lightopenid project is included as a git submodule. So changes made there, can easily be carried over.
Currently it uses only Google for authentication because it's relatively easy to just use the URL "https://www.google.com/accounts/o8/id" (no need for user action). I haven't found out where to redirect users for login through other OpenID providers yet.
Requirements ¶
Yii 1.1.8 or above
Usage ¶
Add as a git submodule:
git submodule add git://github.com/hofrob/LightOpenIdYii.git
Or download the files and put them in the extension directory.
Import the directory through your Yii config file.
'import' => array(
[..]
'ext.LightOpenIdYii.*',
[..]
),
Configure the component.
'components' => array(
[..]
'openid' => array(
'class' => 'LightOpenIdWrapper',
),
[..]
),
You can make use of the UserController provided in this package by mapping it in the config.
'controllerMap' => array(
'user' => array(
'class' => 'ext.LightOpenIdYii.UserController',
),
),
The following views will need to be created:
- loggedin
- cancelled
- logout
In UserIdentity I invoke a static method of my user model to write/load information from my database. Change this to fit your needs.
$this->id = User::syncWithDb($this->openid);
IMPORTANT: You can have two different OpenIDs with Google. One is just a google.com/accounts[..] link. Everyone with a Google account has it. But if you signed up with Google Plus you get a second ID (your Google Plus profile URL). I haven't found out when Google returns which ID. Unfortunately it seems to me that this is random.
You COULD take care of this problem in your database by using the email address as an identifier and connect two IDs where these fields are equal. But don't take my word that this will actually work. It's just an idea.
The difference to the loid extension by GOsha is that the original is updated, unchanged and added as a git submodule.
Links ¶
TODO ¶
- Configure required fields with Yii config files.
- Configure OpenID identifier with Yii config files (Wrapper Line 11).
- Login through other OpenID providers.
How to pass parameters into the wrapper
It's not clear which data (names, values) should be provided to this wrapper to work. There is a UserController example in the package, but it's not documented. In particular, actionLogin contains the following line of code:
$user->openid = $_GET;
What must by in the $_GET at the moment? The only thing which is clear from UserIdentity example, is that there must be 'openid_mode' variable with either 'cancel' or something else(!). Looking at the lightopenid sources makes me think one should provide more info anyway.
I think the wrapper would benefit from better example, because if it requires digging into underlying library, I prefer to use the latter straightaway.
$_GET will be filled by the OpenID Provider (Google)
Thank you for your friendly suggestion.
Have you just tried accessing the actionLogin on your development server? Because it's pretty obvious what happens.
In short:
$_GET = $user->openid = not set
->authenticate() returns nothing
and the user is redirected to start the login process
When he returns he ends up at actionCancelled or actionLoggedin as an authenticated User.
That's ok
Thank you for the prompt reply. ;-) Now I see your point.
In fact, I'm aware about the whole process flow (meaning that openid provider will call your endpoint with its data after successful authentication), but looking at the $__GET line I was not sure that you do not have some view passing initial values just before a user goes to the provider. For example, I'm not aware of 'openid_ext1_value_contact_email', so I thought I missed something.
Anyway, I'd prefer to understand the code before incorporating it into some project for testing. This is why I've grabbed openid.php and plotted a simple code around it without interfering with existing code.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.