Twitch   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDefaultRequestOptions() 0 16 2
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 URL_AUTHORIZE = 'https://api.twitch.tv/kraken/oauth2/authorize';
22
    const URL_EXCHANGE  = 'https://api.twitch.tv/kraken/oauth2/token';
23
    const URL_IDENTIFY  = 'https://api.twitch.tv/kraken/user';
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    const IDENTITY = auth\id\identities\Twitch::class;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    protected $defaultScopes = ['user_read'];
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    protected function getDefaultRequestOptions(auth\interfaces\Token $token = null) : array
39
    {
40
        $options = [
41
            'headers' => [
42
                'Accept' => 'application/vnd.twitchtv.v3+json'
43
            ]
44
        ];
45
46
        // Twitch uses a non-default authorization header.
47
        if (isset($token)) {
48
            $options['headers']['Authorization'] = 'OAuth '.$token->getId();
49
        }
50
51
        // Note: No parent call in the flow.
52
        return $options;
53
    }
54
}
55