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