Reputation: 1901
I started implementing Opauth for CakePHP. It's awesome that it's easy to login via Facebook, Twitter...
Question is once Opauth returns login data what would be an efficient way to login the user to CakePHP?
Opauth doesn't login the user to CakePHP. I think I'm supposed to create a user and save the facebook or other auth info to the db. Is there a plugin that allows me to do this easily?
Upvotes: 2
Views: 1224
Reputation: 120
One thing I love about CakePHP 2.0 was the way the Auth Plugins work, you can really customize one ore more Authentication methods. At the same time this leaves it to the developer to 'hook in' custom Auth Plugins to integrate the solution.
The plugin page has your answer, almost
check step #6
"After validation, user will be redirected to Router::url('/opauth-complete')
with validated auth response data retrievable available at $this->data
"
after this is complete and you have code like their example public function opauth_complete() {...
in this function you will use the $this->data
to find your User that was authenticated
a method I use at times is to find the user by 2 pieces of information that is provided by Opauth example: username and email
you can use something like $loginUser = $this->User->find('first', array('fields'=>array('User.*'), 'conditions'=>array('User.username'=>$this->data['username'], 'User.email'=>$this->data['email']));
once you have the user in $loginUser
you can just call the $this->Auth->login($loginUser)
and you will now have an AuthSession with that user!
Let me know if you have any questions.
Upvotes: 8