1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class DeviantArt |
4
|
|
|
* |
5
|
|
|
* @created 26.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, CSRFToken, OAuth2Provider, ProviderException, TokenRefresh}; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
use function sprintf; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see https://www.deviantart.com/developers/ |
20
|
|
|
*/ |
21
|
|
|
class DeviantArt extends OAuth2Provider implements ClientCredentials, CSRFToken, TokenRefresh{ |
22
|
|
|
|
23
|
|
|
public const SCOPE_BASIC = 'basic'; |
24
|
|
|
public const SCOPE_BROWSE = 'browse'; |
25
|
|
|
public const SCOPE_COLLECTION = 'collection'; |
26
|
|
|
public const SCOPE_COMMENT_POST = 'comment.post'; |
27
|
|
|
public const SCOPE_FEED = 'feed'; |
28
|
|
|
public const SCOPE_GALLERY = 'gallery'; |
29
|
|
|
public const SCOPE_MESSAGE = 'message'; |
30
|
|
|
public const SCOPE_NOTE = 'note'; |
31
|
|
|
public const SCOPE_STASH = 'stash'; |
32
|
|
|
public const SCOPE_USER = 'user'; |
33
|
|
|
public const SCOPE_USER_MANAGE = 'user.manage'; |
34
|
|
|
|
35
|
|
|
protected string $authURL = 'https://www.deviantart.com/oauth2/authorize'; |
36
|
|
|
protected string $accessTokenURL = 'https://www.deviantart.com/oauth2/token'; |
37
|
|
|
protected string $apiURL = 'https://www.deviantart.com/api/v1/oauth2'; |
38
|
|
|
protected ?string $userRevokeURL = 'https://www.deviantart.com/settings/applications'; |
39
|
|
|
protected ?string $apiDocs = 'https://www.deviantart.com/developers/'; |
40
|
|
|
protected ?string $applicationURL = 'https://www.deviantart.com/developers/apps'; |
41
|
|
|
|
42
|
|
|
protected array $defaultScopes = [ |
43
|
|
|
self::SCOPE_BASIC, |
44
|
|
|
self::SCOPE_BROWSE, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritDoc |
49
|
|
|
*/ |
50
|
|
|
public function me():ResponseInterface{ |
51
|
|
|
$response = $this->request('/user/whoami'); |
52
|
|
|
$status = $response->getStatusCode(); |
53
|
|
|
|
54
|
|
|
if($status === 200){ |
55
|
|
|
return $response; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$json = MessageUtil::decodeJSON($response); |
59
|
|
|
|
60
|
|
|
if(isset($json->error, $json->error_description)){ |
61
|
|
|
throw new ProviderException($json->error_description); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
throw new ProviderException(sprintf('user info error error HTTP/%s', $status)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|