Completed
Pull Request — master (#1)
by Alex
35:28 queued 10:15
created

EloquaProvider::getBaseAccessTokenUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Permiakov\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\RequestInterface;
9
use League\OAuth2\Client\Provider\AbstractProvider;
10
use League\OAuth2\Client\Token\AccessToken;
11
12
class EloquaProvider extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
    /**
17
     * @return string
18
     */
19 1
    public function getBaseAuthorizationUrl()
20
    {
21 1
        return 'https://login.eloqua.com/auth/oauth2/authorize';
22
    }
23
24
    /**
25
     * @param array $params
26
     * @return string
27
     */
28 1
    public function getBaseAccessTokenUrl(array $params)
29
    {
30 1
        return 'https://login.eloqua.com/auth/oauth2/token';
31
    }
32
33
    /**
34
     * @param AccessToken $token
35
     * @return string
36
     */
37 1
    public function getResourceOwnerDetailsUrl(AccessToken $token)
38
    {
39 1
        return 'https://login.eloqua.com/id';
40
    }
41
42
    /**
43
     * @return array
44
     */
45 1
    protected function getDefaultScopes()
46
    {
47 1
        return array('full');
48
    }
49
50
    /**
51
     * Authorization and access tokens requests have to be signed with basic auth header
52
     * @return array
53
     */
54 1
    protected function getDefaultHeaders()
55
    {
56 1
        return array('Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret));
57
    }
58
59
    /**
60
     * @param ResponseInterface $response
61
     * @param array|string $data
62
     * @throws IdentityProviderException
63
     */
64 1
    protected function checkResponse(ResponseInterface $response, $data)
65
    {
66 1
        $statusCode = $response->getStatusCode();
67 1
        if (($statusCode < 200 || $statusCode >= 300) ||
68
            isset($data['error'])
69 1
        ) {
70 1
            throw new IdentityProviderException(
71 1
                sprintf(
72 1
                    'Error: %s. Description: %s',
73 1
                    $data['error'],
74 1
                    $data['error_description']
75 1
                ),
76 1
                $statusCode,
77 1
                $response->getBody()
78 1
            );
79
        }
80
    }
81
82
    /**
83
     * @param array $response
84
     * @param AccessToken $token
85
     * @return EloquaResourceOwner
86
     */
87 1
    protected function createResourceOwner(array $response, AccessToken $token)
88
    {
89 1
        $owner = $this->getEloquaResourceOwnerPrototype();
90
91 1
        return $owner->exchangeArray($response);
92
    }
93
94
    /**
95
     * @return EloquaResourceOwner
96
     */
97 1
    protected function getEloquaResourceOwnerPrototype()
98
    {
99 1
        return new EloquaResourceOwner();
100
    }
101
}
102