1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94<?php
/**
* Directus – <http://getdirectus.com>
*
* @link The canonical repository – <https://github.com/directus/directus>
* @copyright Copyright 2006-2017 RANGER Studio, LLC – <http://rangerstudio.com>
* @license GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html>
*/
namespace Directus\Authentication;
use Directus\Application\Application;
use Directus\Config\Config;
/**
* @author Welling Guzmán <welling@rngr.org>
*/
abstract class AbstractSocialProvider implements SocialProviderInterface
{
/**
* @var Application
*/
protected $app;
/**
* @var Config
*/
protected $config;
/**
* @var mixed
*/
protected $provider = null;
/**
* @var string
*/
protected $token = null;
public function __construct(Application $app, array $config)
{
$this->app = $app;
$this->config = new Config($config);
$this->createProvider();
}
/**
* Gets provider instance
*
* @return mixed
*/
public function getProvider()
{
if (!$this->provider) {
$this->createProvider();
}
return $this->provider;
}
/**
* Gets authorization token
*
* @return string|null
*/
public function getToken()
{
return $this->token;
}
/**
* Gets the redirect url for the given service name
*
* @param $name
*
* @return string
*/
public function getRedirectUrl($name)
{
$request = Application::getInstance()->request();
return rtrim($request->getUrl(), '/') . '/auth/' . $name . '/receive';
}
/**
* Creates the provider oAuth client
*
* @return mixed
*/
abstract protected function createProvider();
}