PHP code example of sathomsen / cakephp-facebook-auth

1. Go to this page and download the library: Download sathomsen/cakephp-facebook-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sathomsen / cakephp-facebook-auth example snippets


Configure::write('facebook.appId', 'REPLACE WITH APP ID');
Configure::write('facebook.appSecret', 'REPLACE WITH APP SECRET');
Configure::write('facebook.graphVersion', 'v2.8'); //The api version you intend to use.
Configure::write('facebook.fields', 'id,name,first_name,middle_name,last_name,gender,email');

Configure::write('facebook.identifier', 'REPLACE WITH FACEBOOK IDENTIFIER'));

$this->hasMany('SocialProfiles', [
    'className' => 'SAThomsen/FacebookAuth.SocialProfiles',
    'foreignKey' => 'user_id',
    'dependent' => true,
]);

$this->loadComponent('Auth', [
    'authenticate' => [
        'SAThomsen/FacebookAuth.Facebook',
    ],
]);

// Specifies the username field of the finder
'fields' => [
    'username' => 'email'
],
// Specifies the finder method
'finder' => 'authFB',
// Specifies the header used to transfer token
'header' => 'authorization',
// specifies the identifying prefix used
'prefix' => 'facebook',
// specifies the query parameter to look for in the URL, will be ignored if empty
'parameter' => '',
// specifies the exeption to throw
'unauthenticatedException' => '\Cake\Network\Exception\UnauthorizedException',
// specifies where to find the finder method
'userModel' => 'SAThomsen/FacebookAuth.SocialProfiles',

$this->loadComponent('Auth', [
    'authenticate' => [
        'SAThomsen/FacebookAuth.Facebook' => [
            'fields' => [
                'username' => 'username'
            ],
        ],
    ],
]);

$this->loadComponent('SAThomsen/FacebookAuth.Facebook');