1. Go to this page and download the library: Download dotkernel/dot-auth-social 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/ */
namespace Frontend\User\Controller;
use Dot\Controller\AbstractActionController;
use Dot\AuthSocial\Service\AuthenticationServiceInterface;
use Laminas\Diactoros\Response\RedirectResponse;
use Psr\Http\Message\ResponseInterface;
class FacebookController extends AbstractActionController
{
private AuthenticationServiceInterface $service;
public function __construct(AuthenticationServiceInterface $service)
{
$this->service = $service;
}
public function authAction(): ResponseInterface
{
$code = $this->request->getQueryParams()['code'] ?? false;
if (! $code) {
return new RedirectResponse($this->service->getAuthorizationUrl());
}
$result = $this->service->authenticate($code);
if (! $result->isValid()) {
// invalid authentication, check $result->getMessages() for errors.
} else {
// valid authentication, use $result->getArrayCopy() to get the user details
}
}
}
use Dot\AuthSocial\Service\FacebookService;
use Psr\Container\ContainerInterface;
class FacebookControllerFactory
{
public function __invoke(ContainerInterface $container): FacebookController
{
return new FacebookController($container->get(FacebookService::class));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.