Skip to content

Instantly share code, notes, and snippets.

@majna
Created November 13, 2011 10:57
Show Gist options
  • Select an option

  • Save majna/1361982 to your computer and use it in GitHub Desktop.

Select an option

Save majna/1361982 to your computer and use it in GitHub Desktop.
Cakephp 2 custom Facebook Auth adapter
<?php
App::uses('BaseAuthenticate', 'Controller/Component/Auth');
/**
* Uses the Facebook Connect API to log in a user through the Auth Component.
*
*/
class FacebookAuthenticate extends BaseAuthenticate {
/**
* Settings for this object.
*
* - `fields` The fields to use to identify a user by.
* - `userModel` The model name of the User, defaults to User.
* - `scope` Additional conditions to use when looking up and authenticating users,
* i.e. `array('User.is_active' => 1).`
*
* @var array
* @todo Implement
*/
public $settings = array(
'userModel' => 'Users.User',
'fields' => array('username' => 'email', 'password' => 'password'),
'scope' => array('User.active' => 1)
);
public function authenticate(CakeRequest $request, CakeResponse $response) {
return $this->facebook->getUser(); // your code here..
}
}
@EOM

EOM commented Nov 25, 2011

Copy link
Copy Markdown

One question, I'm new to CakePHP 2 ..

where is the file FacebookAuthenticate..? And sample Use..?
Full Path "/app/.../.."?

Load Vendor App::import('Vendor', 'Facebook'.DS.'facebook'); ..?

thanks

@majna

majna commented Nov 25, 2011

Copy link
Copy Markdown
Author

Put this FacebookAuthenticate.php to app/Controller/Component/Auth/ package.

This is just a proof of concept of configured Auth "adapters"

eg. $this->Auth->authenticate = array('Facebook', 'Form')

@EOM

EOM commented Nov 25, 2011

Copy link
Copy Markdown

thanks, greetings from Argentina ;-)

gracias, saludos desde argentina ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment