|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Risan\OAuth1; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use Risan\OAuth1\Credentials\ClientCredentials; |
|
7
|
|
|
|
|
8
|
|
|
class Config implements ConfigInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The ClientCredentials instance. |
|
12
|
|
|
* |
|
13
|
|
|
* @var \Risan\OAuth1\Credentials\ClientCredentials |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $clientCredentials; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The callback URI. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string|null |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $callbackUri; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The URL for obtaining temporary credentials. Also known as request token |
|
26
|
|
|
* URL. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $temporaryCredentialsUrl; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The URL for asking user to authorize the request. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $authorizationUrl; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The URL for obtaining token credentials. Also known as access token URL. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $tokenCredentialsUrl; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create new instance of Config class. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Risan\OAuth1\Credentials\ClientCredentials $clientCredentials |
|
50
|
|
|
* @param string $temporaryCredentialsUrl |
|
51
|
|
|
* @param string $authorizationUrl |
|
52
|
|
|
* @param string $tokenCredentialsUrl |
|
53
|
|
|
* @param string|null $callbackUri |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(ClientCredentials $clientCredentials, $temporaryCredentialsUrl, $authorizationUrl, $tokenCredentialsUrl, $callbackUri = null) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->clientCredentials = $clientCredentials; |
|
58
|
|
|
$this->temporaryCredentialsUrl = $temporaryCredentialsUrl; |
|
59
|
|
|
$this->authorizationUrl = $authorizationUrl; |
|
60
|
|
|
$this->tokenCredentialsUrl = $tokenCredentialsUrl; |
|
61
|
|
|
$this->callbackUri = $callbackUri; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritDoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getClientCredentials() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->clientCredentials; |
|
70
|
75 |
|
} |
|
71
|
|
|
|
|
72
|
75 |
|
/** |
|
73
|
75 |
|
* {@inheritDoc} |
|
74
|
75 |
|
*/ |
|
75
|
75 |
|
public function getClientCredentialsIdentifier() |
|
76
|
75 |
|
{ |
|
77
|
75 |
|
return $this->getClientCredentials()->getIdentifier(); |
|
78
|
75 |
|
} |
|
79
|
75 |
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritDoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getClientCredentialsSecret() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->getClientCredentials()->getSecret(); |
|
86
|
17 |
|
} |
|
87
|
|
|
|
|
88
|
17 |
|
/** |
|
89
|
|
|
* {@inheritDoc} |
|
90
|
|
|
*/ |
|
91
|
|
|
public function hasCallbackUri() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->getCallbackUri() !== null; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
21 |
|
/** |
|
97
|
|
|
* {@inheritDoc} |
|
98
|
21 |
|
*/ |
|
99
|
|
|
public function getCallbackUri() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->callbackUri; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritDoc} |
|
106
|
8 |
|
*/ |
|
107
|
|
|
public function getTemporaryCredentialsUrl() |
|
108
|
8 |
|
{ |
|
109
|
|
|
return $this->temporaryCredentialsUrl; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritDoc} |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getAuthorizationUrl() |
|
116
|
7 |
|
{ |
|
117
|
|
|
return $this->authorizationUrl; |
|
118
|
7 |
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritDoc} |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getTokenCredentialsUrl() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->tokenCredentialsUrl; |
|
126
|
8 |
|
} |
|
127
|
|
|
|
|
128
|
8 |
|
/** |
|
129
|
|
|
* {@inheritDoc} |
|
130
|
|
|
*/ |
|
131
|
|
|
public static function createFromArray(array $config) |
|
132
|
|
|
{ |
|
133
|
|
|
$requiredParams = [ |
|
134
|
|
|
'client_credentials_identifier', |
|
135
|
|
|
'client_credentials_secret', |
|
136
|
3 |
|
'temporary_credentials_url', |
|
137
|
|
|
'authorization_url', |
|
138
|
3 |
|
'token_credentials_url', |
|
139
|
|
|
]; |
|
140
|
|
|
|
|
141
|
|
|
foreach ($requiredParams as $param) { |
|
142
|
|
|
if (! isset($config[$param])) { |
|
143
|
|
|
throw new InvalidArgumentException("Missing OAuth1 client configuration: {$param}."); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
21 |
|
|
|
147
|
|
|
$callbackUri = isset($config['callback_uri']) ? $config['callback_uri'] : null; |
|
148
|
21 |
|
|
|
149
|
|
|
return new static( |
|
150
|
|
|
new ClientCredentials($config['client_credentials_identifier'], $config['client_credentials_secret']), |
|
151
|
|
|
$config['temporary_credentials_url'], |
|
152
|
|
|
$config['authorization_url'], |
|
153
|
|
|
$config['token_credentials_url'], |
|
154
|
|
|
$callbackUri |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|