friendship ended with social-app. php is my new best friend
1<?php
2/**
3 * Class OpenCaching
4 *
5 * @created 04.03.2019
6 * @author smiley <smiley@chillerlan.net>
7 * @copyright 2019 smiley
8 * @license MIT
9 */
10declare(strict_types=1);
11
12namespace chillerlan\OAuth\Providers;
13
14use chillerlan\OAuth\Core\{AuthenticatedUser, OAuth1Provider, UserInfo};
15use function implode;
16
17/**
18 * Opencaching OAuth1
19 *
20 * @link https://www.opencaching.de/okapi/
21 */
22class OpenCaching extends OAuth1Provider implements UserInfo{
23
24 public const IDENTIFIER = 'OPENCACHING';
25
26 protected const USER_FIELDS = [
27 'uuid', 'username', 'profile_url', 'internal_id', 'date_registered',
28 'caches_found', 'caches_notfound', 'caches_hidden', 'rcmds_given',
29 'rcmds_left', 'rcmd_founds_needed', 'home_location',
30 ];
31
32 protected string $requestTokenURL = 'https://www.opencaching.de/okapi/services/oauth/request_token';
33 protected string $authorizationURL = 'https://www.opencaching.de/okapi/services/oauth/authorize';
34 protected string $accessTokenURL = 'https://www.opencaching.de/okapi/services/oauth/access_token';
35 protected string $apiURL = 'https://www.opencaching.de/okapi/services';
36 protected string|null $userRevokeURL = 'https://www.opencaching.de/okapi/apps/';
37 protected string|null $apiDocs = 'https://www.opencaching.de/okapi/';
38 protected string|null $applicationURL = 'https://www.opencaching.de/okapi/signup.html';
39
40 /** @codeCoverageIgnore */
41 public function me():AuthenticatedUser{
42 $json = $this->getMeResponseData('/users/user', ['fields' => implode('|', $this::USER_FIELDS)]);
43
44 $userdata = [
45 'data' => $json,
46 'handle' => $json['username'],
47 'id' => $json['uuid'],
48 'url' => $json['profile_url'],
49 ];
50
51 return new AuthenticatedUser($userdata);
52 }
53
54}