1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\OAuth2\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth2\Token\StdOAuth2Token; |
6
|
|
|
use OAuth\Common\Http\Exception\TokenResponseException; |
7
|
|
|
use OAuth\Common\Http\Uri\Uri; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Dailymotion service. |
11
|
|
|
* |
12
|
|
|
* @author Mouhamed SEYE <[email protected]> |
13
|
|
|
* @link http://www.dailymotion.com/doc/api/authentication.html |
14
|
|
|
*/ |
15
|
|
|
class Dailymotion extends AbstractService |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Scopes |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
const SCOPE_EMAIL = 'email', |
23
|
|
|
SCOPE_PROFILE = 'userinfo', |
24
|
|
|
SCOPE_VIDEOS = 'manage_videos', |
25
|
|
|
SCOPE_COMMENTS = 'manage_comments', |
26
|
|
|
SCOPE_PLAYLIST = 'manage_playlists', |
27
|
|
|
SCOPE_TILES = 'manage_tiles', |
28
|
|
|
SCOPE_SUBSCRIPTIONS = 'manage_subscriptions', |
29
|
|
|
SCOPE_FRIENDS = 'manage_friends', |
30
|
|
|
SCOPE_FAVORITES = 'manage_favorites', |
31
|
|
|
SCOPE_GROUPS = 'manage_groups'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Dialog form factors |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
const DISPLAY_PAGE = 'page', |
39
|
|
|
DISPLAY_POPUP = 'popup', |
40
|
|
|
DISPLAY_MOBILE = 'mobile'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
protected function init() |
46
|
|
|
{ |
47
|
|
|
if( $this->baseApiUri === null ) { |
|
|
|
|
48
|
|
|
$this->baseApiUri = new Uri('https://api.dailymotion.com/'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getAuthorizationEndpoint() |
56
|
|
|
{ |
57
|
|
|
return new Uri('https://api.dailymotion.com/oauth/authorize'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function getAccessTokenEndpoint() |
64
|
|
|
{ |
65
|
|
|
return new Uri('https://api.dailymotion.com/oauth/token'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
protected function getAuthorizationMethod() |
72
|
|
|
{ |
73
|
|
|
return static::AUTHORIZATION_METHOD_HEADER_OAUTH; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
protected function parseAccessTokenResponse($responseBody) |
80
|
|
|
{ |
81
|
|
|
$data = json_decode($responseBody, true); |
82
|
|
|
|
83
|
|
|
if (null === $data || !is_array($data)) { |
84
|
|
|
throw new TokenResponseException('Unable to parse response.'); |
85
|
|
|
} elseif (isset($data['error_description']) || isset($data['error'])) { |
86
|
|
|
throw new TokenResponseException( |
87
|
|
|
sprintf( |
88
|
|
|
'Error in retrieving token: "%s"', |
89
|
|
|
isset($data['error_description']) ? $data['error_description'] : $data['error'] |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$token = new StdOAuth2Token(); |
95
|
|
|
$token->setAccessToken($data['access_token']); |
96
|
|
|
$token->setLifeTime($data['expires_in']); |
97
|
|
|
|
98
|
|
|
if (isset($data['refresh_token'])) { |
99
|
|
|
$token->setRefreshToken($data['refresh_token']); |
100
|
|
|
unset($data['refresh_token']); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
unset($data['access_token']); |
104
|
|
|
unset($data['expires_in']); |
105
|
|
|
|
106
|
|
|
$token->setExtraParams($data); |
107
|
|
|
|
108
|
|
|
return $token; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
protected function getExtraOAuthHeaders() |
115
|
|
|
{ |
116
|
|
|
return array('Accept' => 'application/json'); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|