1 | <?php |
||
15 | class OAuth1 implements OAuth1ClientInterface |
||
16 | { |
||
17 | use GrantedFlow, |
||
18 | AccessTokenFlow, |
||
19 | RequestTokenFlow, |
||
20 | AuthorizationFlow; |
||
21 | |||
22 | /** |
||
23 | * Http client instance. |
||
24 | * |
||
25 | * @return \OAuth1\Contracts\HttpClientInterface |
||
26 | */ |
||
27 | protected $httpClient; |
||
28 | |||
29 | /** |
||
30 | * Client configuration. |
||
31 | * |
||
32 | * @var \OAuth1\Contracts\ConfigInterface |
||
33 | */ |
||
34 | protected $config; |
||
35 | |||
36 | /** |
||
37 | * OAuth signer instance. |
||
38 | * |
||
39 | * @return \OAuth1\Contracts\Signers\SignerInterface |
||
40 | */ |
||
41 | protected $signer; |
||
42 | |||
43 | /** |
||
44 | * Create a new instance of Generic class. |
||
45 | * |
||
46 | * @param \OAuth1\Contracts\ConfigInterface|array $config |
||
47 | * @param \OAuth1\Contracts\Signers\SignerInterface|null $signer |
||
48 | */ |
||
49 | 56 | public function __construct($config, SignerInterface $signer = null) |
|
50 | { |
||
51 | 56 | if (is_array($config)) { |
|
52 | 56 | $config = Config::fromArray($config); |
|
53 | 56 | } elseif (!$config instanceof ConfigInterface) { |
|
54 | 1 | throw new InvalidArgumentException('OAuth1 client configuration must be a valid array or an instance of OAuth1\Config class.'); |
|
55 | } |
||
56 | |||
57 | 56 | $this->config = $config; |
|
58 | 56 | $this->signer = $signer; |
|
59 | 56 | } |
|
60 | |||
61 | /** |
||
62 | * Get http client instance. |
||
63 | * |
||
64 | * @return \OAuth1\Contracts\HttpClientInterface |
||
65 | */ |
||
66 | 14 | public function httpClient() |
|
74 | |||
75 | /** |
||
76 | * Get client configuration. |
||
77 | * |
||
78 | * @return \OAuth1\Contracts\ConfigInterface |
||
79 | */ |
||
80 | 43 | public function config() |
|
84 | |||
85 | /** |
||
86 | * Get signer. |
||
87 | * |
||
88 | * @return \OAuth1\Contracts\Signers\SignerInterface |
||
89 | */ |
||
90 | 19 | public function signer() |
|
98 | |||
99 | /** |
||
100 | * Generate random nonce. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 16 | public function nonce() |
|
108 | |||
109 | /** |
||
110 | * Get current timestamp. |
||
111 | * |
||
112 | * @return int |
||
113 | */ |
||
114 | 16 | public function timestamp() |
|
118 | |||
119 | /** |
||
120 | * Get OAuth version. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | 16 | public function version() |
|
128 | |||
129 | /** |
||
130 | * Get OAuth base protocol parameters. |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 15 | public function baseProtocolParameters() |
|
144 | |||
145 | /** |
||
146 | * Build authorization headers. |
||
147 | * |
||
148 | * @param array $parameters |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 15 | public function authorizationHeaders(array $parameters) |
|
158 | } |
||
159 |