Getting started with OpenID and PHP

Written: Aug 9th 2009, 14:14

Growing number of web applications and multiple numbers of user accounts can be a headache for the end user. Luckily the big players have started to agree on standards that makes the personal information flow between these services.

2 standards

Open ID
  • OpenId:“http://openid.net/” – enable the user to login via an other site where they already have an account, in a registration proccess the new application will be able to retrieve information as nickname, full name, etc.
  • OAuth:“http://oauth.net/” – mostly used when you are creating an application for one specific web service as Twitter

PHP and OpenID

There are several implementation for PHP and OpenID In my first start I first tried EasyOpenID from codymays.net but found that it bugged when the OpenID provider return back to my script, so I went for the PHP OpenID Library from openidenabled.com

Setting up PHP OpenID Library

Actually it worked right out of the box, I had some problems but they were connected to the OpenID providers. Even though many services say they support OpenID, many of them seem to be a little buggy! So you need to get use myopenid.com to try out this. (First try with Claimid.com gave me an error, and Yahoo.com do not yet support OpenID Simple Registration Extension – so you can request personal information).

  1. You can do this on your localhost server, just but the downloaded “PHP OpenID Library from openidenabled.com” (see link above) and put it ~/Sites/php-openid-2.1.3 (on a mac).
  2. You might want to change the change the $store_path on line 53 in “examples/consumer/commom.php” to something else than “/tmp” directory
  3. Then open your browser and go to localhost and locate “http://localhost/~username/php-openid-2.1.3/examples/consumer/” and enter your myopenid address: http://username.myopenid.com/ If you have created a Personas you will be able to allow your localhost application to receive this information before you are returned to your local script.

Further stuff to do

There is a pretty good guide on Plaxo to how you can build in OpenID in your own application. This adding a database table to hold the each users multiple OpenId url’s, with a relation to your current user table. For new users you can request the basic information you need so the user don’t have to retype this information, and populate your user table with this.

For CakePHP there is an OpenID component made by CakeBaker but it only allow sole OpenID login and no relation with your current user table.

For Ez publish there is an OpenID extension

Download files

Back to posts list