Created
November 13, 2011 10:57
-
-
Save majna/1361982 to your computer and use it in GitHub Desktop.
Cakephp 2 custom Facebook Auth adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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.. | |
| } | |
| } |
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')
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
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