1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Provider\Oauth2Facebook; |
13
|
|
|
|
14
|
|
|
use League\OAuth2\Client\Provider\Facebook; |
15
|
|
|
use Phalcon\Di\DiInterface; |
16
|
|
|
use Phalcon\Session\Manager; |
17
|
|
|
use Zemit\Config\ConfigInterface; |
18
|
|
|
use Zemit\Http\Request; |
19
|
|
|
use Zemit\Provider\AbstractServiceProvider; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @link https://github.com/tegaphilip/padlock |
23
|
|
|
* @link https://oauth2.thephpleague.com/framework-integrations/ |
24
|
|
|
*/ |
25
|
|
|
class ServiceProvider extends AbstractServiceProvider |
26
|
|
|
{ |
27
|
|
|
protected string $serviceName = 'oauth2Facebook'; |
28
|
|
|
|
29
|
|
|
public function register(DiInterface $di): void |
30
|
|
|
{ |
31
|
|
|
$di->setShared($this->getName(), function () use ($di) { |
32
|
|
|
|
33
|
|
|
$config = $di->get('config'); |
34
|
|
|
assert($config instanceof ConfigInterface); |
35
|
|
|
|
36
|
|
|
$session = $di->get('session'); |
37
|
|
|
assert($session instanceof Manager); |
38
|
|
|
|
39
|
|
|
$request = $di->get('request'); |
40
|
|
|
assert($request instanceof Request); |
41
|
|
|
|
42
|
|
|
$oauthConfig = $config->pathToArray('oauth2') ?? []; |
43
|
|
|
$oauthFacebookConfig = $oauthConfig['facebook'] ?? []; |
44
|
|
|
|
45
|
|
|
// Set the full url |
46
|
|
|
$secure = $request->isSecure(); |
47
|
|
|
$scheme = $request->getScheme() . '://'; |
48
|
|
|
$host = $request->getHttpHost(); |
49
|
|
|
$port = $request->getPort(); |
50
|
|
|
$port = ($port !== $secure ? '443' : '80') ? ':' . $port : null; |
51
|
|
|
$oauthFacebookConfig['redirectUri'] = $scheme . $host . $port . ($oauthFacebookConfig['redirectUri'] ?: ''); |
52
|
|
|
|
53
|
|
|
return new Facebook($oauthFacebookConfig); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|