1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Njasm\Soundcloud\Auth; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* SoundCloud API wrapper in PHP |
9
|
|
|
* |
10
|
|
|
* @author Nelson J Morais <[email protected]> |
11
|
|
|
* @copyright 2014 Nelson J Morais <[email protected]> |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
13
|
|
|
* @link http://github.com/njasm/soundcloud |
14
|
|
|
* @package Njasm\Soundcloud |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
class Auth implements AuthInterface |
18
|
|
|
{ |
19
|
|
|
private $clientID; |
20
|
|
|
private $clientSecret; |
21
|
|
|
private $authUrlCallback; |
22
|
|
|
|
23
|
|
|
private $accessToken; |
24
|
|
|
private $expires; |
25
|
|
|
private $scope; |
26
|
|
|
private $refreshToken; |
27
|
|
|
|
28
|
38 |
|
public function __construct($clientID = null, $clientSecret = null, $authUrlCallback = null) |
29
|
|
|
{ |
30
|
38 |
|
if ($this->isValidClientID($clientID) === false) { |
31
|
1 |
|
throw new \InvalidArgumentException("No ClientID Provided."); |
32
|
|
|
} |
33
|
|
|
|
34
|
37 |
|
$this->clientID = $clientID; |
35
|
37 |
|
$this->clientSecret = $clientSecret; |
36
|
37 |
|
$this->authUrlCallback = $authUrlCallback; |
37
|
37 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $clientID |
41
|
|
|
* @return boolean |
42
|
|
|
*/ |
43
|
38 |
|
private function isValidClientID($clientID) |
44
|
|
|
{ |
45
|
38 |
|
return is_string($clientID) === true && empty($clientID) === false; |
46
|
|
|
} |
47
|
|
|
|
48
|
8 |
|
public function getClientID() |
49
|
|
|
{ |
50
|
8 |
|
return $this->clientID; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
public function getClientSecret() |
54
|
|
|
{ |
55
|
2 |
|
return $this->clientSecret; |
56
|
|
|
} |
57
|
|
|
|
58
|
4 |
|
public function getAuthUrlCallback() |
59
|
|
|
{ |
60
|
4 |
|
return $this->authUrlCallback; |
61
|
|
|
} |
62
|
|
|
|
63
|
5 |
|
public function setToken($token) |
64
|
|
|
{ |
65
|
5 |
|
$this->accessToken = $token; |
66
|
5 |
|
} |
67
|
|
|
|
68
|
4 |
|
public function getToken() |
69
|
|
|
{ |
70
|
4 |
|
return $this->accessToken; |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
public function hasToken() |
74
|
|
|
{ |
75
|
2 |
|
return empty($this->accessToken) === false ? true : false; |
76
|
|
|
} |
77
|
|
|
|
78
|
4 |
|
public function setScope($scope) |
79
|
|
|
{ |
80
|
4 |
|
$this->scope = $scope; |
81
|
4 |
|
} |
82
|
|
|
|
83
|
2 |
|
public function getScope() |
84
|
|
|
{ |
85
|
2 |
|
return $this->scope; |
86
|
|
|
} |
87
|
|
|
|
88
|
4 |
|
public function setExpires($expires) |
89
|
|
|
{ |
90
|
4 |
|
$this->expires = $expires; |
91
|
4 |
|
} |
92
|
|
|
|
93
|
2 |
|
public function getExpires() |
94
|
|
|
{ |
95
|
2 |
|
return $this->expires; |
96
|
|
|
} |
97
|
|
|
|
98
|
4 |
|
public function setRefreshToken($refreshToken) |
99
|
|
|
{ |
100
|
4 |
|
$this->refreshToken = $refreshToken; |
101
|
4 |
|
} |
102
|
|
|
|
103
|
2 |
|
public function getRefreshToken() |
104
|
|
|
{ |
105
|
2 |
|
return $this->refreshToken; |
106
|
|
|
} |
107
|
|
|
|
108
|
13 |
|
public function mergeParams(array $params = array(), $includeClientSecret = false) |
109
|
|
|
{ |
110
|
13 |
|
if ($this->accessToken !== null) { |
111
|
1 |
|
return array_merge($params, array('oauth_token' => $this->accessToken)); |
112
|
|
|
} |
113
|
|
|
|
114
|
13 |
|
if ($includeClientSecret === true) { |
115
|
4 |
|
$params = array_merge($params, array('client_secret' => $this->clientSecret)); |
116
|
|
|
} |
117
|
|
|
|
118
|
13 |
|
return array_merge($params, array('client_id' => $this->clientID)); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|