|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
declare(strict_types=1); |
|
7
|
|
|
|
|
8
|
|
|
namespace SocialConnect\OAuth2\Provider; |
|
9
|
|
|
|
|
10
|
|
|
use SocialConnect\Common\ArrayHydrator; |
|
11
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
|
12
|
|
|
use SocialConnect\Common\Entity\User; |
|
13
|
|
|
|
|
14
|
|
|
class Steein extends \SocialConnect\OAuth2\AbstractProvider |
|
15
|
|
|
{ |
|
16
|
|
|
const NAME = 'steein'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
4 |
|
public function getBaseUri() |
|
22
|
|
|
{ |
|
23
|
4 |
|
return 'https://www.steein.ru/'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
2 |
|
public function getAuthorizeUri() |
|
30
|
|
|
{ |
|
31
|
2 |
|
return 'https://www.steein.ru/oauth/authorize'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
2 |
|
public function getRequestTokenUri() |
|
38
|
|
|
{ |
|
39
|
2 |
|
return 'https://www.steein.ru/oauth/token'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
3 |
|
public function getName() |
|
46
|
|
|
{ |
|
47
|
3 |
|
return self::NAME; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function getScopeInline() |
|
54
|
|
|
{ |
|
55
|
1 |
|
return implode(' ', $this->scope); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritDoc} |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void |
|
62
|
|
|
{ |
|
63
|
3 |
|
if ($accessToken) { |
|
64
|
3 |
|
$headers['Authorization'] = "Bearer {$accessToken->getToken()}"; |
|
65
|
|
|
} |
|
66
|
3 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
3 |
|
public function getIdentity(AccessTokenInterface $accessToken) |
|
72
|
|
|
{ |
|
73
|
3 |
|
$response = $this->request('GET', 'api/v2.0/users/show', [], $accessToken); |
|
74
|
|
|
|
|
75
|
1 |
|
$hydrator = new ArrayHydrator([ |
|
76
|
1 |
|
'displayName' => 'fullname', |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
/** @var User $user */ |
|
80
|
1 |
|
$user = $hydrator->hydrate(new User(), $response); |
|
81
|
|
|
|
|
82
|
1 |
|
if ($response['name']) { |
|
83
|
1 |
|
if ($response['name']['first_name']) { |
|
84
|
1 |
|
$user->firstname = $response['name']['first_name']; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
if ($response['name']['last_name']) { |
|
88
|
1 |
|
$user->lastname = $response['name']['last_name']; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
return $user; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|