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