Completed
Push — master ( 50beb4...8d6a23 )
by Michał
02:12
created

Twitch::getDefaultRequestOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php namespace nyx\auth\id\protocols\oauth2\providers;
2
3
// Internal dependencies
4
use nyx\auth\id\protocols\oauth2;
5
use nyx\auth;
6
7
/**
8
 * Twitch Identity Provider (OAuth 2.0)
9
 *
10
 * @package     Nyx\Auth
11
 * @version     0.1.0
12
 * @author      Michal Chojnacki <[email protected]>
13
 * @copyright   2012-2017 Nyx Dev Team
14
 * @link        https://github.com/unyx/nyx
15
 */
16
class Twitch extends oauth2\Provider
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    const SCOPE_SEPARATOR = ' ';
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    const URL_AUTHORIZE = 'https://api.twitch.tv/kraken/oauth2/authorize';
27
    const URL_EXCHANGE  = 'https://api.twitch.tv/kraken/oauth2/token';
28
    const URL_IDENTIFY  = 'https://api.twitch.tv/kraken/user';
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    const IDENTITY = auth\id\identities\Twitch::class;
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    protected $defaultScopes = ['user_read'];
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 View Code Duplication
    protected function getDefaultRequestOptions(auth\interfaces\Token $token = null) : array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $options = [
46
            'headers' => [
47
                'Accept' => 'application/vnd.twitchtv.v3+json'
48
            ]
49
        ];
50
51
        // Twitch uses a non-default authorization header.
52
        if (null !== $token) {
53
            $options['headers']['Authorization'] = 'OAuth '.$token->getId();
54
        }
55
56
        // Note: No parent call in the flow.
57
        return $options;
58
    }
59
}
60