Integrating cakephp with OpenId
| July 26, 2012 | Posted by kaswan under Cakephp |
Today everyone is in a rapid hustle. So mostly internet users find registration process as very time consuming. Sometimes they might leave your web product if they just want to avoid that annoying registration process. So a very good alternative to this is using OpenId. OpenId is a great way to make your authentication system even more flexible.
Prerequisites
First of all your PHP must have OpenID Library. You can download it from this Link. When you are done with downloading library then extract the folder named as Auth into your web application’s /app/vendors/ folder.
/app/vendors/ not /vendors/ which is in root of your web app besides your app folder.Second you must have OpenId plugin for Cakephp. To download this plugin follow this link. Now similarly extract this download to your /app/plugins/ folder. After extracting you will have openid folder inside your /app/plugins/.
Coding
- First of all you need to replace that OpenId’s Auth component with cakephp’s default Auth component. To do that edit your
appcontroller.phpfile. By implementing below code will extend Auth component functionality. One thing that is very important here is that you still have power of old Auth Component. You can still use it’s variables and functions i.e$this->Auth->allow("*"); - Now you need to edit your
login.ctpview file. When below form is submitted then Auth component will try to login user with username and password field. But if it failed to login with username and password then it will check whether OpenId URL is specified or not. If this happens then it will attempt to authenticate URL against OpenID server. If permission granted then OpenAuth component will add user to the session.
|
1 2 3 |
var $components = array( 'Openid.OpenAuth' ); |
|
1 2 3 4 5 6 7 |
<?php echo $this->Form->create(array('action'=>'login')); echo $this->Form->input(array('openid' => array('label' => 'OpenID URL'))); echo $this->Form->input('username'); echo $this->Form->input('password'); echo $this->Form->end('Login'); ?> |
Final words
This is it, after this all we have working authentication system with OpenId.
-
dream_coder
-
Leon
-
http://robhasawiki.com/index.php?title=User:XVASusana Increase traffic Software



