Completed
Push — 3.x ( ca6623...f673a3 )
by Дмитрий
03:24
created

Apple::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 * @author Alexander Fedyashov <[email protected]>
6
 */
7
declare(strict_types=1);
8
9
namespace SocialConnect\OpenIDConnect\Provider;
10
11
use SocialConnect\Common\ArrayHydrator;
12
use SocialConnect\Common\Entity\User;
13
use SocialConnect\Common\Exception\InvalidArgumentException;
14
use SocialConnect\Common\Exception\Unsupported;
15
use SocialConnect\OpenIDConnect\AccessToken;
16
use SocialConnect\Provider\AccessTokenInterface;
17
use SocialConnect\OpenIDConnect\AbstractProvider;
18
19
/**
20
 * @link https://developer.apple.com/sign-in-with-apple/get-started/
21
 */
22
class Apple extends AbstractProvider
23
{
24
    const NAME = 'apple';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getOpenIdUrl()
30
    {
31
        throw new Unsupported('Apple does not support openid-configuration url');
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function discover(): array
38
    {
39
        return [
40
            'jwks_uri' => 'https://appleid.apple.com/auth/keys'
41
        ];
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function getBaseUri()
48
    {
49 1
        return 'https://appleid.apple.com/';
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function getAuthorizeUri()
56
    {
57 1
        return 'https://appleid.apple.com/auth/authorize';
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function getRequestTokenUri()
64
    {
65 1
        return 'https://appleid.apple.com/auth/token';
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 1
    public function getName()
72
    {
73 1
        return self::NAME;
74
    }
75
76
    /**
77
     * I didnt find
78
     *
79
     * {@inheritdoc}
80
     */
81 1
    public function getIdentity(AccessTokenInterface $accessToken)
82
    {
83 1
        if (!$accessToken instanceof AccessToken) {
84
            throw new InvalidArgumentException(
85
                '$accessToken must be instance AccessToken'
86
            );
87
        }
88
89 1
        $jwt = $accessToken->getJwt();
90
91 1
        $hydrator = new ArrayHydrator([
92 1
            'email' => 'email',
93
            'email_verified' => 'emailVerified '
94
        ]);
95
96
        /** @var User $user */
97 1
        $user = $hydrator->hydrate(new User(), $jwt->getPayload());
98
99 1
        return $user;
100
    }
101
}
102