Completed
Push — master ( bbc890...eddbee )
by Carlos
02:07 queued 33s
created

OutlookProvider::getAuthUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the overtrue/socialite.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Overtrue\Socialite\Providers;
13
14
use Overtrue\Socialite\AccessTokenInterface;
15
use Overtrue\Socialite\ProviderInterface;
16
use Overtrue\Socialite\User;
17
18
/**
19
 * Class OutlookProvider.
20
 */
21
class OutlookProvider extends AbstractProvider implements ProviderInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected $scopes = ['User.Read'];
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected $scopeSeparator = ' ';
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function getAuthUrl($state)
37
    {
38
        return $this->buildAuthUrlFromBase('https://login.microsoftonline.com/common/oauth2/v2.0/authorize', $state);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function getTokenUrl()
45
    {
46
        return 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 View Code Duplication
    protected function getUserByToken(AccessTokenInterface $token)
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...
53
    {
54
        $response = $this->getHttpClient()->get(
55
            'https://graph.microsoft.com/v1.0/me',
56
            ['headers' => [
57
                'Accept'        => 'application/json',
58
                'Authorization' => 'Bearer ' . $token->getToken(),
59
            ],
60
            ]);
61
62
        return json_decode($response->getBody()->getContents(), true);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 View Code Duplication
    protected function mapUserToObject(array $user)
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...
69
    {
70
        return new User([
71
            'id'       => $this->arrayItem($user, 'id'),
72
            'nickname' => null,
73
            'name'     => $this->arrayItem($user, 'displayName'),
74
            'email'    => $this->arrayItem($user, 'userPrincipalName'),
75
            'avatar'   => null,
76
        ]);
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    protected function getTokenFields($code)
83
    {
84
        return array_merge(parent::getTokenFields($code), [
85
            'grant_type' => 'authorization_code',
86
        ]);
87
    }
88
}
89