MonzoProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 59
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTokenUrl() 0 3 1
A getAuthUrl() 0 3 1
A mapUserToObject() 0 4 1
A getUserByToken() 0 9 1
A getTokenFields() 0 4 1
1
<?php
2
3
namespace Amelia\Monzo\Socialite;
4
5
use Laravel\Socialite\Two\User;
6
use Laravel\Socialite\Two\AbstractProvider;
7
use Laravel\Socialite\Two\ProviderInterface;
8
9
class MonzoProvider extends AbstractProvider implements ProviderInterface
10
{
11
    /**
12
     * Unique Provider Identifier.
13
     */
14
    const IDENTIFIER = 'MONZO';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $scopes = [];
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected function getAuthUrl($state)
25
    {
26
        return $this->buildAuthUrlFromBase('https://auth.monzo.com/', $state);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function getTokenUrl()
33
    {
34
        return 'https://api.monzo.com/oauth2/token';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function getUserByToken($token)
41
    {
42
        $response = $this->getHttpClient()->get('https://api.monzo.com/ping/whoami', [
43
            'headers' => [
44
                'Authorization' => 'Bearer ' . $token,
45
            ],
46
        ]);
47
48
        return json_decode($response->getBody(), true);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function mapUserToObject(array $user)
55
    {
56
        return (new User())->setRaw($user)->map([
57
            'id' => $user['user_id'],
58
        ]);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    protected function getTokenFields($code)
65
    {
66
        return array_merge(parent::getTokenFields($code), [
67
            'grant_type' => 'authorization_code',
68
        ]);
69
    }
70
}
71