Completed
Push — master ( 2af3c5...bcfbb1 )
by Hirofumi
02:49
created

BaseProvider::getAuthorizationHeaders()   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 Shippinno\Base\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 Psr\Http\Message\ResponseInterface;
10
11
class BaseProvider extends AbstractProvider
12
{
13
    /**
14
     * Returns the base URL for authorizing a client.
15
     *
16
     * @return string
17
     */
18 1
    public function getBaseAuthorizationUrl()
19
    {
20 1
        return 'https://api.thebase.in/1/oauth/authorize';
21
    }
22
23
    /**
24
     * Returns the base URL for requesting an access token.
25
     *
26
     * Eg. https://oauth.service.com/token
27
     *
28
     * @param array $params
29
     * @return string
30
     */
31 3
    public function getBaseAccessTokenUrl(array $params)
32
    {
33 3
        return 'https://api.thebase.in/1/oauth/token';
34
    }
35
36
    /**
37
     * Returns the URL for requesting the resource owner's details.
38
     *
39
     * @param AccessToken $token
40
     * @return string
41
     */
42 2
    public function getResourceOwnerDetailsUrl(AccessToken $token)
43
    {
44 2
        return 'https://api.thebase.in/1/users/me';
45
    }
46
47
    /**
48
     * Returns the default scopes used by this provider.
49
     *
50
     * This should only be the scopes that are required to request the details
51
     * of the resource owner, rather than all the available scopes.
52
     *
53
     * @return string[]
54
     */
55 1
    protected function getDefaultScopes()
56
    {
57 1
        return ['read_users'];
58
    }
59
60
    /**
61
     * Checks a provider response for errors.
62
     *
63
     * @throws IdentityProviderException
64
     * @param  ResponseInterface $response
65
     * @param  array|string $data Parsed response data
66
     * @return void
67
     */
68 3
    protected function checkResponse(ResponseInterface $response, $data)
69
    {
70 3
        if (isset($data['error'])) {
71 1
            throw new IdentityProviderException(
72 1
                $data['error'] ?: $response->getReasonPhrase(),
73 1
                $response->getStatusCode(),
74 1
                $response->getBody()
75 1
            );
76
        }
77 2
    }
78
79
    /**
80
     * Generates a resource owner object from a successful resource owner
81
     * details request.
82
     *
83
     * @param  array $response
84
     * @param  AccessToken $token
85
     * @return ResourceOwnerInterface
86
     */
87 1
    protected function createResourceOwner(array $response, AccessToken $token)
88
    {
89 1
        return new BaseResourceOwner($response);
90
    }
91
92
    /**
93
     * Returns the authorization headers used by this provider.
94
     *
95
     * @param  mixed|null $token Either a string or an access token instance
96
     * @return array
97
     */
98 1
    public function getAuthorizationHeaders($token = null)
99
    {
100 1
        return array('Authorization' => 'Bearer '.$token->getToken());
101
    }
102
103
    /**
104
     * Returns the string that should be used to separate scopes when building
105
     * the URL for requesting an access token.
106
     *
107
     * @return string Scope separator
108
     */
109 1
    protected function getScopeSeparator()
110
    {
111 1
        return '+';
112
    }
113
}
114