Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
|
0.00% |
0 / 26 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
|
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
get_service_credentials | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
perform_auth_login | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
perform_token_auth | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\auth\provider\oauth\service; |
15 | |
16 | /** |
17 | * Twitter OAuth service |
18 | */ |
19 | class twitter extends base |
20 | { |
21 | /** @var \phpbb\config\config */ |
22 | protected $config; |
23 | |
24 | /** @var \phpbb\request\request_interface */ |
25 | protected $request; |
26 | |
27 | /** |
28 | * Constructor. |
29 | * |
30 | * @param \phpbb\config\config $config Config object |
31 | * @param \phpbb\request\request_interface $request Request object |
32 | */ |
33 | public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request) |
34 | { |
35 | $this->config = $config; |
36 | $this->request = $request; |
37 | } |
38 | |
39 | /** |
40 | * {@inheritdoc} |
41 | */ |
42 | public function get_service_credentials() |
43 | { |
44 | return [ |
45 | 'key' => $this->config['auth_oauth_twitter_key'], |
46 | 'secret' => $this->config['auth_oauth_twitter_secret'], |
47 | ]; |
48 | } |
49 | |
50 | /** |
51 | * {@inheritdoc} |
52 | */ |
53 | public function perform_auth_login() |
54 | { |
55 | if (!($this->service_provider instanceof \OAuth\OAuth1\Service\Twitter)) |
56 | { |
57 | throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); |
58 | } |
59 | |
60 | $storage = $this->service_provider->getStorage(); |
61 | |
62 | try |
63 | { |
64 | /** @var \OAuth\OAuth1\Token\TokenInterface $token */ |
65 | $token = $storage->retrieveAccessToken('Twitter'); |
66 | } |
67 | catch (\OAuth\Common\Storage\Exception\TokenNotFoundException $e) |
68 | { |
69 | throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST'); |
70 | } |
71 | |
72 | $secret = $token->getRequestTokenSecret(); |
73 | |
74 | try |
75 | { |
76 | // This was a callback request, get the token |
77 | $this->service_provider->requestAccessToken( |
78 | $this->request->variable('oauth_token', ''), |
79 | $this->request->variable('oauth_verifier', ''), |
80 | $secret |
81 | ); |
82 | } |
83 | catch (\OAuth\Common\Http\Exception\TokenResponseException $e) |
84 | { |
85 | throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST'); |
86 | } |
87 | |
88 | // Send a request with it |
89 | $result = (array) json_decode($this->service_provider->request('account/verify_credentials.json'), true); |
90 | |
91 | // Return the unique identifier |
92 | return $result['id']; |
93 | } |
94 | |
95 | /** |
96 | * {@inheritdoc} |
97 | */ |
98 | public function perform_token_auth() |
99 | { |
100 | if (!($this->service_provider instanceof \OAuth\OAuth1\Service\Twitter)) |
101 | { |
102 | throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); |
103 | } |
104 | |
105 | // Send a request with it |
106 | $result = (array) json_decode($this->service_provider->request('account/verify_credentials.json'), true); |
107 | |
108 | // Return the unique identifier |
109 | return $result['id']; |
110 | } |
111 | } |