junker/facebook-canvas-service-provider

Facebook Canvas Service Provider for Silex

0.2.3 2020-06-20 12:54 UTC

This package is auto-updated.

Last update: 2024-12-20 23:11:06 UTC


README

Facebook Canvas Service Provider for Silex

Requirements

silex 2.x

Installation

The best way to install FacebookCanvasServiceProvider is to use a Composer:

composer require junker/facebook-canvas-service-provider

Examples

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
			]
	],
];

UserProvider Must implements FacebookCanvasUserProviderInterface

<?php
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);
	}

	....
}