|
| 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 | + */ |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace chillerlan\OAuth\Providers; |
| 15 | + |
| 16 | +use chillerlan\OAuth\Core\{AuthenticatedUser, CSRFToken, OAuth2Provider, TokenRefresh, UserInfo}; |
| 17 | +use function sprintf; |
| 18 | + |
| 19 | +/** |
| 20 | + * @see https://developers.pinterest.com/docs/getting-started/authentication/ |
| 21 | + */ |
| 22 | +class Pinterest extends OAuth2Provider implements CSRFToken, TokenRefresh, UserInfo{ |
| 23 | + |
| 24 | + public const SCOPE_ADS_READ = 'ads:read'; |
| 25 | + public const SCOPE_ADS_WRITE = 'ads:write'; |
| 26 | + public const SCOPE_BOARDS_READ = 'boards:read'; |
| 27 | + public const SCOPE_BOARDS_READ_SECRET = 'boards:read_secret'; |
| 28 | + public const SCOPE_BOARDS_WRITE = 'boards:write'; |
| 29 | + public const SCOPE_BOARDS_WRITE_SECRET = 'boards:write_secret'; |
| 30 | + public const SCOPE_CATALOGS_READ = 'catalogs:read'; |
| 31 | + public const SCOPE_CATALOGS_WRITE = 'catalogs:write'; |
| 32 | + public const SCOPE_PINS_READ = 'pins:read'; |
| 33 | + public const SCOPE_PINS_READ_SECRET = 'pins:read_secret'; |
| 34 | + public const SCOPE_PINS_WRITE = 'pins:write'; |
| 35 | + public const SCOPE_PINS_WRITE_SECRET = 'pins:write_secret'; |
| 36 | + public const SCOPE_USER_ACCOUNTS_READ = 'user_accounts:read'; |
| 37 | + |
| 38 | + public const DEFAULT_SCOPES = [ |
| 39 | + self::SCOPE_BOARDS_READ, |
| 40 | + self::SCOPE_PINS_READ, |
| 41 | + self::SCOPE_USER_ACCOUNTS_READ, |
| 42 | + ]; |
| 43 | + |
| 44 | + public const USES_BASIC_AUTH_IN_ACCESS_TOKEN_REQUEST = true; |
| 45 | + |
| 46 | + protected string $authorizationURL = 'https://www.pinterest.com/oauth/'; |
| 47 | + protected string $accessTokenURL = 'https://api.pinterest.com/v5/oauth/token'; |
| 48 | + protected string $apiURL = 'https://api.pinterest.com'; |
| 49 | + protected string|null $apiDocs = 'https://developers.pinterest.com/docs/'; |
| 50 | + protected string|null $applicationURL = 'https://developers.pinterest.com/apps/'; |
| 51 | + protected string|null $userRevokeURL = 'https://www.pinterest.com/settings/security'; |
| 52 | + |
| 53 | + /** |
| 54 | + * @inheritDoc |
| 55 | + * @codeCoverageIgnore |
| 56 | + */ |
| 57 | + public function me():AuthenticatedUser{ |
| 58 | + $json = $this->getMeResponseData('/v5/user_account'); |
| 59 | + |
| 60 | + $userdata = [ |
| 61 | + 'data' => $json, |
| 62 | + 'avatar' => $json['profile_image'], |
| 63 | + 'handle' => $json['username'], |
| 64 | + 'id' => $json['id'], |
| 65 | + 'url' => sprintf('https://www.pinterest.com/%s/', $json['username']), |
| 66 | + ]; |
| 67 | + |
| 68 | + return new AuthenticatedUser($userdata); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments