friendship ended with social-app. php is my new best friend
1<?php
2/**
3 * Class Pinterest
4 *
5 * @created 07.04.2024
6 * @author smiley <smiley@chillerlan.net>
7 * @copyright 2024 smiley
8 * @license MIT
9 *
10 * @noinspection PhpUnused
11 */
12declare(strict_types=1);
13
14namespace chillerlan\OAuth\Providers;
15
16use chillerlan\OAuth\Core\{AuthenticatedUser, CSRFToken, OAuth2Provider, TokenRefresh, UserInfo};
17use function sprintf;
18
19/**
20 * Pinterest OAuth2
21 *
22 * @link https://developers.pinterest.com/docs/getting-started/authentication/
23 */
24class Pinterest extends OAuth2Provider implements CSRFToken, TokenRefresh, UserInfo{
25
26 public const IDENTIFIER = 'PINTEREST';
27
28 public const SCOPE_ADS_READ = 'ads:read';
29 public const SCOPE_ADS_WRITE = 'ads:write';
30 public const SCOPE_BOARDS_READ = 'boards:read';
31 public const SCOPE_BOARDS_READ_SECRET = 'boards:read_secret';
32 public const SCOPE_BOARDS_WRITE = 'boards:write';
33 public const SCOPE_BOARDS_WRITE_SECRET = 'boards:write_secret';
34 public const SCOPE_CATALOGS_READ = 'catalogs:read';
35 public const SCOPE_CATALOGS_WRITE = 'catalogs:write';
36 public const SCOPE_PINS_READ = 'pins:read';
37 public const SCOPE_PINS_READ_SECRET = 'pins:read_secret';
38 public const SCOPE_PINS_WRITE = 'pins:write';
39 public const SCOPE_PINS_WRITE_SECRET = 'pins:write_secret';
40 public const SCOPE_USER_ACCOUNTS_READ = 'user_accounts:read';
41
42 public const DEFAULT_SCOPES = [
43 self::SCOPE_BOARDS_READ,
44 self::SCOPE_PINS_READ,
45 self::SCOPE_USER_ACCOUNTS_READ,
46 ];
47
48 public const USES_BASIC_AUTH_IN_ACCESS_TOKEN_REQUEST = true;
49
50 protected string $authorizationURL = 'https://www.pinterest.com/oauth/';
51 protected string $accessTokenURL = 'https://api.pinterest.com/v5/oauth/token';
52 protected string $apiURL = 'https://api.pinterest.com';
53 protected string|null $apiDocs = 'https://developers.pinterest.com/docs/';
54 protected string|null $applicationURL = 'https://developers.pinterest.com/apps/';
55 protected string|null $userRevokeURL = 'https://www.pinterest.com/settings/security';
56
57 /** @codeCoverageIgnore */
58 public function me():AuthenticatedUser{
59 $json = $this->getMeResponseData('/v5/user_account');
60
61 $userdata = [
62 'data' => $json,
63 'avatar' => $json['profile_image'],
64 'handle' => $json['username'],
65 'id' => $json['id'],
66 'url' => sprintf('https://www.pinterest.com/%s/', $json['username']),
67 ];
68
69 return new AuthenticatedUser($userdata);
70 }
71
72}