1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class SoundCloud |
4
|
|
|
* |
5
|
|
|
* @created 22.10.2017 |
6
|
|
|
* @author Smiley <[email protected]> |
7
|
|
|
* @copyright 2017 Smiley |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace chillerlan\OAuth\Providers; |
12
|
|
|
|
13
|
|
|
use chillerlan\HTTP\Utils\MessageUtil; |
14
|
|
|
use chillerlan\OAuth\Core\{ClientCredentials, OAuth2Provider, ProviderException, TokenRefresh}; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
use function sprintf; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see https://developers.soundcloud.com/ |
20
|
|
|
* @see https://developers.soundcloud.com/docs/api/guide#authentication |
21
|
|
|
* @see https://developers.soundcloud.com/blog/security-updates-api |
22
|
|
|
*/ |
23
|
|
|
class SoundCloud extends OAuth2Provider implements ClientCredentials, TokenRefresh{ |
24
|
|
|
|
25
|
|
|
public const SCOPE_NONEXPIRING = 'non-expiring'; |
26
|
|
|
# public const SCOPE_EMAIL = 'email'; // ??? |
27
|
|
|
|
28
|
|
|
protected string $authURL = 'https://api.soundcloud.com/connect'; |
29
|
|
|
protected string $accessTokenURL = 'https://api.soundcloud.com/oauth2/token'; |
30
|
|
|
protected string $apiURL = 'https://api.soundcloud.com'; |
31
|
|
|
protected ?string $userRevokeURL = 'https://soundcloud.com/settings/connections'; |
32
|
|
|
protected ?string $apiDocs = 'https://developers.soundcloud.com/'; |
33
|
|
|
protected ?string $applicationURL = 'https://soundcloud.com/you/apps'; |
34
|
|
|
protected string $authMethodHeader = 'OAuth'; |
35
|
|
|
|
36
|
|
|
protected array $defaultScopes = [ |
37
|
|
|
self::SCOPE_NONEXPIRING, |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritDoc |
42
|
|
|
*/ |
43
|
|
|
public function me():ResponseInterface{ |
44
|
|
|
$response = $this->request('/me'); |
45
|
|
|
$status = $response->getStatusCode(); |
46
|
|
|
|
47
|
|
|
if($status === 200){ |
48
|
|
|
return $response; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$json = MessageUtil::decodeJSON($response); |
52
|
|
|
|
53
|
|
|
if(isset($json->status)){ |
54
|
|
|
throw new ProviderException($json->status); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
throw new ProviderException(sprintf('user info error error HTTP/%s', $status)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|