-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscogs.php
54 lines (44 loc) · 1.71 KB
/
Discogs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Class Discogs
*
* @created 08.04.2018
* @author Smiley <smiley@chillerlan.net>
* @copyright 2018 Smiley
* @license MIT
*/
declare(strict_types=1);
namespace chillerlan\OAuth\Providers;
use chillerlan\OAuth\Core\{AuthenticatedUser, OAuth1Provider, UserInfo};
use function sprintf;
/**
* Discogs OAuth1
*
* @link https://www.discogs.com/developers/
* @link https://www.discogs.com/developers/#page:authentication,header:authentication-oauth-flow
*/
class Discogs extends OAuth1Provider implements UserInfo{
public const IDENTIFIER = 'DISCOGS';
public const HEADERS_API = [
'Accept' => 'application/vnd.discogs.v2.discogs+json',
];
protected string $requestTokenURL = 'https://api.discogs.com/oauth/request_token';
protected string $authorizationURL = 'https://www.discogs.com/oauth/authorize';
protected string $accessTokenURL = 'https://api.discogs.com/oauth/access_token';
protected string $apiURL = 'https://api.discogs.com';
protected string|null $userRevokeURL = 'https://www.discogs.com/settings/applications';
protected string|null $apiDocs = 'https://www.discogs.com/developers/';
protected string|null $applicationURL = 'https://www.discogs.com/settings/developers';
/** @codeCoverageIgnore */
public function me():AuthenticatedUser{
$json = $this->getMeResponseData('/oauth/identity');
// we could do a second request to [resource_url] for the avatar and more info, but that's not really worth it.
$userdata = [
'data' => $json,
'handle' => $json['username'],
'id' => $json['id'],
'url' => sprintf('https://www.discogs.com/user/%s', $json['username']),
];
return new AuthenticatedUser($userdata);
}
}