diff --git a/.config/.env_example b/.config/.env_example index 3e7c39c..f0ab01f 100644 --- a/.config/.env_example +++ b/.config/.env_example @@ -188,6 +188,12 @@ PAYPAL_SANDBOX_SECRET= PAYPAL_SANDBOX_CALLBACK_URL= #PAYPAL_SANDBOX_TESTUSER= +# https://developers.pinterest.com/apps/ +PINTEREST_KEY= +PINTEREST_SECRET= +PINTEREST_CALLBACK_URL= +#PINTEREST_TESTUSER= + # https://www.reddit.com/prefs/apps/ REDDIT_KEY= REDDIT_SECRET= diff --git a/README.md b/README.md index ec63c8d..2cdf3e3 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ Note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc | [Patreon](https://docs.patreon.com/) | [link](https://www.patreon.com/portal/registration/register-clients) | | 2 | ✓ | ✓ | | | ✓ | | | [PayPal](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 | ✓ | ✓ | | ✓ | ✓ | | | [PayPalSandbox](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 | ✓ | ✓ | | ✓ | ✓ | | +| [Pinterest](https://developers.pinterest.com/docs/) | [link](https://developers.pinterest.com/apps/) | [link](https://www.pinterest.com/settings/security) | 2 | ✓ | ✓ | | | ✓ | | | [Reddit](https://www.reddit.com/dev/api) | [link](https://www.reddit.com/prefs/apps/) | [link](https://www.reddit.com/settings/privacy) | 2 | ✓ | ✓ | | ✓ | ✓ | ✓ | | [Slack](https://api.slack.com) | [link](https://api.slack.com/apps) | [link](https://slack.com/apps/manage) | 2 | ✓ | ✓ | | | | | | [SoundCloud](https://developers.soundcloud.com/) | [link](https://soundcloud.com/you/apps) | [link](https://soundcloud.com/settings/connections) | 2 | ✓ | | | ✓ | ✓ | | diff --git a/docs/Basics/Overview.md b/docs/Basics/Overview.md index d3ba166..9381553 100644 --- a/docs/Basics/Overview.md +++ b/docs/Basics/Overview.md @@ -68,6 +68,7 @@ fully [PSR-7](https://www.php-fig.org/psr/psr-7/)/[PSR-17](https://www.php-fig.o | [Patreon](https://docs.patreon.com/) | [link](https://www.patreon.com/portal/registration/register-clients) | | 2 | ✓ | ✓ | | | ✓ | | | [PayPal](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 | ✓ | ✓ | | ✓ | ✓ | | | [PayPalSandbox](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 | ✓ | ✓ | | ✓ | ✓ | | +| [Pinterest](https://developers.pinterest.com/docs/) | [link](https://developers.pinterest.com/apps/) | [link](https://www.pinterest.com/settings/security) | 2 | ✓ | ✓ | | | ✓ | | | [Reddit](https://www.reddit.com/dev/api) | [link](https://www.reddit.com/prefs/apps/) | [link](https://www.reddit.com/settings/privacy) | 2 | ✓ | ✓ | | ✓ | ✓ | ✓ | | [Slack](https://api.slack.com) | [link](https://api.slack.com/apps) | [link](https://slack.com/apps/manage) | 2 | ✓ | ✓ | | | | | | [SoundCloud](https://developers.soundcloud.com/) | [link](https://soundcloud.com/you/apps) | [link](https://soundcloud.com/settings/connections) | 2 | ✓ | | | ✓ | ✓ | | diff --git a/examples/get-token/Pinterest.php b/examples/get-token/Pinterest.php new file mode 100644 index 0000000..432dc81 --- /dev/null +++ b/examples/get-token/Pinterest.php @@ -0,0 +1,23 @@ + + * @copyright 2024 Smiley + * @license MIT + */ +declare(strict_types=1); + +use chillerlan\OAuth\Providers\Pinterest; + +$ENVVAR ??= 'PINTEREST'; + +require_once __DIR__.'/../provider-example-common.php'; + +/** @var \OAuthExampleProviderFactory $factory */ +$provider = $factory->getProvider(Pinterest::class, $ENVVAR); + +require_once __DIR__.'/_flow-oauth2.php'; + +exit; diff --git a/src/Providers/Pinterest.php b/src/Providers/Pinterest.php new file mode 100644 index 0000000..4abfedb --- /dev/null +++ b/src/Providers/Pinterest.php @@ -0,0 +1,71 @@ + + * @copyright 2024 smiley + * @license MIT + * + * @noinspection PhpUnused + */ +declare(strict_types=1); + +namespace chillerlan\OAuth\Providers; + +use chillerlan\OAuth\Core\{AuthenticatedUser, CSRFToken, OAuth2Provider, TokenRefresh, UserInfo}; +use function sprintf; + +/** + * @see https://developers.pinterest.com/docs/getting-started/authentication/ + */ +class Pinterest extends OAuth2Provider implements CSRFToken, TokenRefresh, UserInfo{ + + public const SCOPE_ADS_READ = 'ads:read'; + public const SCOPE_ADS_WRITE = 'ads:write'; + public const SCOPE_BOARDS_READ = 'boards:read'; + public const SCOPE_BOARDS_READ_SECRET = 'boards:read_secret'; + public const SCOPE_BOARDS_WRITE = 'boards:write'; + public const SCOPE_BOARDS_WRITE_SECRET = 'boards:write_secret'; + public const SCOPE_CATALOGS_READ = 'catalogs:read'; + public const SCOPE_CATALOGS_WRITE = 'catalogs:write'; + public const SCOPE_PINS_READ = 'pins:read'; + public const SCOPE_PINS_READ_SECRET = 'pins:read_secret'; + public const SCOPE_PINS_WRITE = 'pins:write'; + public const SCOPE_PINS_WRITE_SECRET = 'pins:write_secret'; + public const SCOPE_USER_ACCOUNTS_READ = 'user_accounts:read'; + + public const DEFAULT_SCOPES = [ + self::SCOPE_BOARDS_READ, + self::SCOPE_PINS_READ, + self::SCOPE_USER_ACCOUNTS_READ, + ]; + + public const USES_BASIC_AUTH_IN_ACCESS_TOKEN_REQUEST = true; + + protected string $authorizationURL = 'https://www.pinterest.com/oauth/'; + protected string $accessTokenURL = 'https://api.pinterest.com/v5/oauth/token'; + protected string $apiURL = 'https://api.pinterest.com'; + protected string|null $apiDocs = 'https://developers.pinterest.com/docs/'; + protected string|null $applicationURL = 'https://developers.pinterest.com/apps/'; + protected string|null $userRevokeURL = 'https://www.pinterest.com/settings/security'; + + /** + * @inheritDoc + * @codeCoverageIgnore + */ + public function me():AuthenticatedUser{ + $json = $this->getMeResponseData('/v5/user_account'); + + $userdata = [ + 'data' => $json, + 'avatar' => $json['profile_image'], + 'handle' => $json['username'], + 'id' => $json['id'], + 'url' => sprintf('https://www.pinterest.com/%s/', $json['username']), + ]; + + return new AuthenticatedUser($userdata); + } + +} diff --git a/tests/Providers/Live/PinterestAPITest.php b/tests/Providers/Live/PinterestAPITest.php new file mode 100644 index 0000000..2b6d81d --- /dev/null +++ b/tests/Providers/Live/PinterestAPITest.php @@ -0,0 +1,31 @@ + + * @copyright 2024 smiley + * @license MIT + */ +declare(strict_types=1); + +namespace chillerlan\OAuthTest\Providers\Live; + +use chillerlan\OAuth\Providers\Pinterest; +use PHPUnit\Framework\Attributes\Group; + +/** + * @property \chillerlan\OAuth\Providers\Pinterest $provider + */ +#[Group('providerLiveTest')] +class PinterestAPITest extends OAuth2ProviderLiveTestAbstract{ + + protected function getProviderFQCN():string{ + return Pinterest::class; + } + + protected function getEnvPrefix():string{ + return 'PINTEREST'; + } + +} diff --git a/tests/Providers/Unit/PinterestTest.php b/tests/Providers/Unit/PinterestTest.php new file mode 100644 index 0000000..26122d9 --- /dev/null +++ b/tests/Providers/Unit/PinterestTest.php @@ -0,0 +1,25 @@ + + * @copyright 2024 smiley + * @license MIT + */ +declare(strict_types=1); + +namespace chillerlan\OAuthTest\Providers\Unit; + +use chillerlan\OAuth\Providers\Pinterest; + +/** + * @property \chillerlan\OAuth\Providers\Pinterest $provider + */ +class PinterestTest extends OAuth2ProviderUnitTestAbstract{ + + protected function getProviderFQCN():string{ + return Pinterest::class; + } + +}