Skip to content

Commit

Permalink
✨ +Pinterest provider
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Apr 9, 2024
1 parent d61fb64 commit 45085cd
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .config/.env_example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || | ||| |
Expand Down
1 change: 1 addition & 0 deletions docs/Basics/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || | ||| |
Expand Down
23 changes: 23 additions & 0 deletions examples/get-token/Pinterest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @link https://developers.pinterest.com/docs/getting-started/authentication/
*
* @created 09.04.2024
* @author smiley <[email protected]>
* @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;
71 changes: 71 additions & 0 deletions src/Providers/Pinterest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Class Pinterest
*
* @created 07.04.2024
* @author smiley <[email protected]>
* @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);
}

}
31 changes: 31 additions & 0 deletions tests/Providers/Live/PinterestAPITest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Class PinterestAPITest
*
* @created 09.04.2024
* @author smiley <[email protected]>
* @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';
}

}
25 changes: 25 additions & 0 deletions tests/Providers/Unit/PinterestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Class PinterestTest
*
* @created 08.04.2024
* @author smiley <[email protected]>
* @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;
}

}

0 comments on commit 45085cd

Please sign in to comment.