PHP code example of junker / facebook-canvas-service-provider

1. Go to this page and download the library: Download junker/facebook-canvas-service-provider 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/ */

    

junker / facebook-canvas-service-provider example snippets


use Junker\Silex\Provider\FacebookCanvasServiceProvider;

$app['users'] = function() use ($app) { return new MyApp\UserProvider($app['db']); };

$app['security.firewalls'] =  [
	'fb_canvas' => [		
			'pattern' => '^/fb_canvas/',
			'users' => $app['users'],
			'anonymous' => true,
			'facebook_canvas' => [
				'login_path' => '/registration',
				'app_secret' => $facebook_app_secret
			]
	],
];




namespace MyApp;

use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;

use Junker\Silex\Security\User\FacebookCanvasUserProviderInterface;

class UserProvider implements UserProviderInterface,FacebookCanvasUserProviderInterface
{
	private $db;

	public function __construct($db)
	{
		$this->db = $db;
	}
 
	public function loadUserByFacebookUid($fbUid)
	{
		$username = $this->db->fetchColumn('SELECT username FROM user WHERE facebook_uid=?', [$fbUid]);

		return $this->loadUserByUsername($username);
	}

	....
}