Skip to content

CakePHP Authentication Plugin to Sign in with Facebook, Twitter, Google and Linkedin

Notifications You must be signed in to change notification settings

news2u/cakephp-social-sign-in

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SocialSignin Plugin

About

A CakePHP plugin to sign in with Facebook, Twitter, Google and Linkedin account.

Target APIs

  • Facebook
  • Linkedin
  • Twitter
  • Google Account (OAuth 2.0 only)

Requirements

  • CakePHP 2.0/2.1
  • PECL oauth extension
  • service API keys to work with

Installation

To install to plugin directoroy of your CakePHP application

cd my/app/Plugin
git clone [email protected]:news2u/cakephp-social-sign-in.git SocialSignIn

How to use

Works as an Authenticate Component. The below is sample setting of Facebook sign in.

class AppController extends Controller {
    ...
    public function beforeFilter() {
        ....
        $this->Auth->authenticate = array(
            'SocialSignIn.Facebook' => array(
                'userModel' => 'User',
                'fields' => array('username' => 'facebook_user_id'),
                'app_id' => '__YOUR_APP_ID__',
                'app_secret' => '__YOUR_APP_SECRET__',
                'redirect_uri' => '__YOUR_APP_LOGIN_URI__',
                'session' => 'FaecbookAuthenticate',
            )
        );
    }
    $this->helpers['SocialSignIn.Facebook'] = array(
        'app_id' => '__YOUR_APP_ID__',
        'redirect_uri' => '__YOUR_APP_LOGIN_URI__',
    );
    ....
}

And put "Sign in with Facebook" link in your Login page

$this->Facebook->signin(__('Sigin in with Facebook account'));

How to connect with user

Authenticate component stores each Social account information to Session, both whether user is found or not.

$facebook = $this->Session->read('FacebookAuthenticate');
$this->User->saveField('facebook_user_id', $facebook->id);

How to know user using which account to sign in.

CakePHP does not pass the infomation which authentication component is used to login directly. If it needed the below code may help.

private function _login_method() {
    $login_method = null;
    $objs = $this->Auth->constructAuthenticate();
    foreach ($objs as $obj) {
         preg_match(/^(.+)Authenticate/', get_class($obj), $m);
         $name = $m[1];
         if ($obj->authenticate($this->request, $this->response)) {
             $login_method = $name;
         ]
    }
    return $login_method;
}

Copyright and License

Copyright 2012 News2u Corporation

MIT License (http://www.opensource.org/licenses/mit-license.php)

About

CakePHP Authentication Plugin to Sign in with Facebook, Twitter, Google and Linkedin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published