|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Risan\OAuth1\Request; |
|
4
|
|
|
|
|
5
|
|
|
use Risan\OAuth1\Credentials\TemporaryCredentials; |
|
6
|
|
|
|
|
7
|
|
|
class AuthorizationHeader implements AuthorizationHeaderInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The ProtocolParameterInterface instance. |
|
11
|
|
|
* |
|
12
|
|
|
* @var \Risan\OAuth1\Request\ProtocolParameterInterface |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $protocolParameter; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Create a new instance of AuthorizationHeader class. |
|
18
|
|
|
* |
|
19
|
|
|
* @param \Risan\OAuth1\Request\ProtocolParameterInterface $protocolParameter |
|
20
|
|
|
*/ |
|
21
|
5 |
|
public function __construct(ProtocolParameterInterface $protocolParameter) |
|
22
|
|
|
{ |
|
23
|
5 |
|
$this->protocolParameter = $protocolParameter; |
|
24
|
5 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritDoc} |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function getProtocolParameter() |
|
30
|
|
|
{ |
|
31
|
1 |
|
return $this->protocolParameter; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritDoc} |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function getConfig() |
|
38
|
|
|
{ |
|
39
|
1 |
|
return $this->protocolParameter->getConfig(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritDoc} |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function forTemporaryCredentials() |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->normalizeProtocolParameters( |
|
48
|
1 |
|
$this->protocolParameter->forTemporaryCredentials() |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritDoc} |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function forTokenCredentials(TemporaryCredentials $temporaryCredentials, $verificationCode) |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->normalizeProtocolParameters( |
|
58
|
1 |
|
$this->protocolParameter->forTokenCredentials($temporaryCredentials, $verificationCode) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritDoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function normalizeProtocolParameters(array $parameters) |
|
66
|
|
|
{ |
|
67
|
3 |
|
array_walk($parameters, function (&$value, $key) { |
|
68
|
3 |
|
$value = rawurlencode($key) . '="' . rawurlencode($value) . '"'; |
|
69
|
3 |
|
}); |
|
70
|
|
|
|
|
71
|
|
|
return 'OAuth ' . implode(', ', $parameters); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|