|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace SocialConnect\Vimeo; |
|
8
|
|
|
|
|
9
|
|
|
use SocialConnect\Auth\Exception\InvalidAccessToken; |
|
10
|
|
|
use SocialConnect\Auth\Provider\OAuth2\AccessToken; |
|
11
|
|
|
use SocialConnect\Common\Entity\User; |
|
12
|
|
|
use SocialConnect\Common\Hydrator\ObjectMap; |
|
13
|
|
|
|
|
14
|
|
|
class Provider extends \SocialConnect\Auth\Provider\OAuth2\AbstractProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var User|null |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $user; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getBaseUri() |
|
25
|
|
|
{ |
|
26
|
|
|
return 'https://api.vimeo.com/'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getAuthorizeUri() |
|
33
|
|
|
{ |
|
34
|
|
|
return 'https://api.vimeo.com/oauth/authorize'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getRequestTokenUri() |
|
41
|
|
|
{ |
|
42
|
|
|
return 'https://api.vimeo.com/oauth/access_token'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getName() |
|
49
|
|
|
{ |
|
50
|
|
|
return 'vimeo'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function parseToken($body) |
|
57
|
|
|
{ |
|
58
|
|
|
$response = json_decode($body, false); |
|
59
|
|
|
if ($response) { |
|
60
|
|
|
// Vimeo return User on get Access Token Request (looks like to protect round trips) |
|
61
|
|
|
if (isset($response->user)) { |
|
62
|
|
|
$hydrator = new ObjectMap(array( |
|
63
|
|
|
'name' => 'fullname', |
|
64
|
|
|
)); |
|
65
|
|
|
|
|
66
|
|
|
$this->user = $hydrator->hydrate(new User(), $response->user); |
|
67
|
|
|
$this->user->id = str_replace('/users/', '', $this->user->uri); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($response->access_token)) { |
|
71
|
|
|
return new AccessToken($response->access_token); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
throw new InvalidAccessToken('access_token field does not exists inside API JSON response'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
throw new InvalidAccessToken('AccessToken is not a valid JSON'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getIdentity(AccessToken $accessToken) |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->user; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|