YConnect::getBaseAccessTokenUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: polidog
5
 * Date: 2016/11/09
6
 */
7
8
namespace Tavii\OAuth2\Client\Provider;
9
10
11
use League\OAuth2\Client\Provider\AbstractProvider;
12
use League\OAuth2\Client\Token\AccessToken;
13
use Psr\Http\Message\ResponseInterface;
14
use Tavii\OAuth2\Client\Provider\Exception\YConnectIdentityProviderException;
15
16
class YConnect extends AbstractProvider
17
{
18
    const API_DOMAIN = 'https://auth.login.yahoo.co.jp';
19
20
    const USERINFO_DOMAIN = 'https://userinfo.yahooapis.jp';
21
22
    public $version = 'v1';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function getBaseAuthorizationUrl()
28
    {
29 4
        return $this->getApiBaseUrl().'/authorization';
30
    }
31
32
    protected function getAuthorizationHeaders($token = null)
33
    {
34
        if ($token != null) {
35
            return ['Authorization' => 'Bearer '.$token];
36
        }
37
        return [];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 4
    public function getBaseAccessTokenUrl(array $params)
44
    {
45 4
        return $this->getApiBaseUrl().'/token';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    protected function getAccessTokenOptions(array $params)
52
    {
53 2
        $options = parent::getAccessTokenOptions([
54 2
            'code' => $params['code'],
55 2
            'grant_type' => 'authorization_code',
56 2
            'redirect_uri' => $params['redirect_uri'],
57 2
        ]);
58
59 2
        $options['headers']['Authorization'] = 'Basic '.base64_encode($params['client_id']. ':' . $params['client_secret']);
60 2
        return $options;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getResourceOwnerDetailsUrl(AccessToken $token)
67
    {
68
        return $this->getUserInfoBaseUrl().'/attribute?schema=openid';
69
    }
70
71
72
    public function getAuthenticatedRequest($method, $url, $token, array $options = [])
73
    {
74
        return $this->createRequest($method, $url, $token, $options);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 4
    protected function getDefaultScopes()
81
    {
82
        return [
83 4
            'openid',
84 4
        ];
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 2
    protected function checkResponse(ResponseInterface $response, $data)
91
    {
92 2
        if ($response->getStatusCode() >= 400) {
93
            throw YConnectIdentityProviderException::clientException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 90 can also be of type string; however, Tavii\OAuth2\Client\Prov...tion::clientException() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94 2
        } elseif (isset($data['error'])) {
95
            throw YConnectIdentityProviderException::oauthException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 90 can also be of type string; however, Tavii\OAuth2\Client\Prov...ption::oauthException() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
96
        }
97 2
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    protected function createResourceOwner(array $response, AccessToken $token)
103
    {
104
        return new YConnectResourceOwner($response);
105
    }
106
107 8
    protected function getApiBaseUrl()
108
    {
109 8
        return static::API_DOMAIN. "/yconnect/".$this->version;
110
    }
111
112
    protected function getUserInfoBaseUrl()
113
    {
114
        return static::USERINFO_DOMAIN. '/yconnect/'.$this->version;
115
    }
116
}