|
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\Provider\Exception\InvalidAccessToken; |
|
13
|
|
|
use SocialConnect\OAuth2\AccessToken; |
|
14
|
|
|
use SocialConnect\Common\Entity\User; |
|
15
|
|
|
|
|
16
|
|
|
class Vimeo extends \SocialConnect\OAuth2\AbstractProvider |
|
17
|
|
|
{ |
|
18
|
|
|
const NAME = 'vimeo'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var User|null |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $user; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public function getBaseUri() |
|
29
|
|
|
{ |
|
30
|
1 |
|
return 'https://api.vimeo.com/'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function getAuthorizeUri() |
|
37
|
|
|
{ |
|
38
|
2 |
|
return 'https://api.vimeo.com/oauth/authorize'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
2 |
|
public function getRequestTokenUri() |
|
45
|
|
|
{ |
|
46
|
2 |
|
return 'https://api.vimeo.com/oauth/access_token'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function getName() |
|
53
|
|
|
{ |
|
54
|
3 |
|
return self::NAME; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public function parseToken(string $body) |
|
61
|
|
|
{ |
|
62
|
4 |
|
if (empty($body)) { |
|
63
|
1 |
|
throw new InvalidAccessToken('Provider response with empty body'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
3 |
|
$response = json_decode($body, true); |
|
67
|
3 |
|
if ($response) { |
|
68
|
1 |
|
$token = new AccessToken($response); |
|
69
|
|
|
|
|
70
|
|
|
// Vimeo return User on get Access Token Request (looks like to protect round trips) |
|
71
|
1 |
|
if (isset($response['user'])) { |
|
72
|
|
|
$hydrator = new ArrayHydrator([ |
|
73
|
|
|
'name' => 'fullname', |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
|
|
$this->user = $hydrator->hydrate(new User(), $response['user']); |
|
77
|
|
|
$this->user->id = str_replace('/users/', '', $this['user']['uri']); |
|
78
|
|
|
|
|
79
|
|
|
$token->setUserId((string) $this->user->id); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
return $token; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
2 |
|
throw new InvalidAccessToken('AccessToken is not a valid JSON'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* {@inheritdoc} |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getIdentity(AccessTokenInterface $accessToken) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->user; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|