Completed
Push — master ( b5c2a9...ab10ed )
by Atymic
06:11
created

src/OAuth1/Server.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SocialiteProviders\Manager\OAuth1;
4
5
use GuzzleHttp\Exception\BadResponseException;
6
use League\OAuth1\Client\Credentials\TemporaryCredentials;
7
use League\OAuth1\Client\Server\Server as BaseServer;
8
use SocialiteProviders\Manager\ConfigTrait;
9
10
abstract class Server extends BaseServer
11
{
12
    use ConfigTrait;
13
14
    /**
15
     * The custom parameters to be sent with the request.
16
     *
17
     * @var array
18
     */
19
    protected $parameters = [];
20
21
    /**
22
     * The scopes being requested.
23
     *
24
     * @var array
25
     */
26
    protected $scopes = [];
27
28
    /**
29
     * The separating character for the requested scopes.
30
     *
31
     * @var string
32
     */
33
    protected $scopeSeparator = ',';
34
35
    /**
36
     * Retrieves token credentials by passing in the temporary credentials,
37
     * the temporary credentials identifier as passed back by the server
38
     * and finally the verifier code.
39
     *
40
     * @param \League\OAuth1\Client\Credentials\TemporaryCredentials $temporaryCredentials
41
     * @param string                                                 $temporaryIdentifier
42
     * @param string                                                 $verifier
43
     *
44
     * @return \League\OAuth1\Client\Credentials\TokenCredentials
45
     */
46
    public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier)
47
    {
48
        if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) {
49
            throw new \InvalidArgumentException(
50
                'Temporary identifier passed back by server does not match that of stored temporary credentials.
51
                Potential man-in-the-middle.'
52
            );
53
        }
54
55
        $uri = $this->urlTokenCredentials();
56
        $bodyParameters = ['oauth_verifier' => $verifier];
57
58
        $client = $this->createHttpClient();
59
60
        $headers = $this->getHeaders($temporaryCredentials, 'POST', $uri, $bodyParameters);
61
62
        try {
63
            if ('GuzzleHttp\\Client' === get_class($client)) {
64
                $response = $client->post($uri, [
65
                    'headers'     => $headers,
66
                    'form_params' => $bodyParameters,
67
                ]);
68
            } else {
69
                $response = $client->post($uri, $headers, $bodyParameters)->send();
70
            }
71
        } catch (BadResponseException $e) {
72
            return $this->handleTokenCredentialsBadResponse($e);
0 ignored issues
show
$e is of type object<GuzzleHttp\Exception\BadResponseException>, but the function expects a object<Guzzle\Http\Excep...n\BadResponseException>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
        }
74
75
        return [
76
            'tokenCredentials'        => $this->createTokenCredentials($response->getBody()),
77
            'credentialsResponseBody' => $response->getBody(),
78
        ];
79
    }
80
81
    /**
82
     * Set the scopes of the requested access.
83
     *
84
     * @param array $scopes
85
     *
86
     * @return $this
87
     */
88
    public function scopes(array $scopes)
89
    {
90
        $this->scopes = array_unique(array_merge($this->scopes, $scopes));
91
92
        return $this;
93
    }
94
95
    /**
96
     * Set the custom parameters of the request.
97
     *
98
     * @param array $parameters
99
     *
100
     * @return $this
101
     */
102
    public function with(array $parameters)
103
    {
104
        $this->parameters = $parameters;
105
106
        return $this;
107
    }
108
109
    /**
110
     * Format the given scopes.
111
     *
112
     * @param array  $scopes
113
     * @param string $scopeSeparator
114
     *
115
     * @return string
116
     */
117
    protected function formatScopes(array $scopes, $scopeSeparator)
118
    {
119
        return implode($scopeSeparator, $scopes);
120
    }
121
}
122