Completed
Push — master ( d7f813...438a72 )
by Chris
04:16
created

Drupal::getDefaultScopes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ChrisHemmings\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
8
use League\OAuth2\Client\Token\AccessToken;
9
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
10
use Psr\Http\Message\ResponseInterface;
11
12
class Drupal extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
    protected $baseUrl;
17
18 21
    public function getBaseUrl()
19
    {
20 21
        return $this->baseUrl;
21
    }
22
23
    /**
24
     * Get provider url to run authorization
25
     *
26
     * @return string
27
     */
28 6
    public function getBaseAuthorizationUrl()
29
    {
30 6
        return $this->getBaseUrl() . '/oauth2/authorize';
31
    }
32
33
    /**
34
     * Returns the base URL for requesting an access token.
35
     *
36
     * @param array $params
37
     * @return string
38
     */
39
    public function getBaseAccessTokenUrl(array $params)
40 12
    {
41
        return $this->getBaseUrl() . '/oauth2/token';
42 12
    }
43
44
    /**
45
     * Get provider url to fetch user details
46
     *
47
     * @param AccessToken $token
48
     * @return string
49
     */
50
    public function getResourceOwnerDetailsUrl(AccessToken $token)
51
    {
52 3
        return $this->getBaseUrl() . '/oauth2/UserInfo';
53
    }
54 3
55
    /**
56
     * Get the default scopes used by this provider.
57
     *
58
     * @return array
59
     */
60
    protected function getDefaultScopes()
61
    {
62
        return ['openid', 'email', 'profile'];
63
    }
64 3
65
    /**
66 3
     * Returns the string that should be used to separate scopes when building
67 3
     * the URL for requesting an access token.
68
     *
69 3
     * @return string Scope separator, defaults to ' '
70
     */
71
    protected function getScopeSeparator()
72
    {
73
        return ' ';
74
    }
75
76
    /**
77 6
     * Check a provider response for errors.
78
     *
79 6
     * @param ResponseInterface $response
80
     * @param array|string $data
81
     *
82
     * @throws IdentityProviderException
83
     */
84
    protected function checkResponse(ResponseInterface $response, $data)
85
    {
86
        if ($response->getStatusCode() >= 400) {
87
            throw new IdentityProviderException(
88 6
                $data['error'] ?: $response->getReasonPhrase(),
89
                $response->getStatusCode(),
90 6
                $response
0 ignored issues
show
Documentation introduced by
$response is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a array|string.

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...
91
            );
92
        }
93
    }
94
95
    /**
96
     * Generate a user object from a successful user details request.
97
     *
98
     * @param array $response
99
     * @param AccessToken $token
100
     *
101 9
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
102
     */
103 9
    protected function createResourceOwner(array $response, AccessToken $token)
104 3
    {
105 3
        return new DrupalResourceOwner($response);
106 3
    }
107
}
108