Skip to content

Commit 45085cd

Browse files
committed
✨ +Pinterest provider
1 parent d61fb64 commit 45085cd

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-0
lines changed

.config/.env_example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ PAYPAL_SANDBOX_SECRET=
188188
PAYPAL_SANDBOX_CALLBACK_URL=
189189
#PAYPAL_SANDBOX_TESTUSER=
190190

191+
# https://developers.pinterest.com/apps/
192+
PINTEREST_KEY=
193+
PINTEREST_SECRET=
194+
PINTEREST_CALLBACK_URL=
195+
#PINTEREST_TESTUSER=
196+
191197
# https://www.reddit.com/prefs/apps/
192198
REDDIT_KEY=
193199
REDDIT_SECRET=

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc
129129
| [Patreon](https://docs.patreon.com/) | [link](https://www.patreon.com/portal/registration/register-clients) | | 2 ||| | || |
130130
| [PayPal](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 ||| ||| |
131131
| [PayPalSandbox](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 ||| ||| |
132+
| [Pinterest](https://developers.pinterest.com/docs/) | [link](https://developers.pinterest.com/apps/) | [link](https://www.pinterest.com/settings/security) | 2 ||| | || |
132133
| [Reddit](https://www.reddit.com/dev/api) | [link](https://www.reddit.com/prefs/apps/) | [link](https://www.reddit.com/settings/privacy) | 2 ||| ||||
133134
| [Slack](https://api.slack.com) | [link](https://api.slack.com/apps) | [link](https://slack.com/apps/manage) | 2 ||| | | | |
134135
| [SoundCloud](https://developers.soundcloud.com/) | [link](https://soundcloud.com/you/apps) | [link](https://soundcloud.com/settings/connections) | 2 || | ||| |

docs/Basics/Overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fully [PSR-7](https://www.php-fig.org/psr/psr-7/)/[PSR-17](https://www.php-fig.o
6868
| [Patreon](https://docs.patreon.com/) | [link](https://www.patreon.com/portal/registration/register-clients) | | 2 ||| | || |
6969
| [PayPal](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 ||| ||| |
7070
| [PayPalSandbox](https://developer.paypal.com/docs/connect-with-paypal/reference/) | [link](https://developer.paypal.com/developer/applications/) | | 2 ||| ||| |
71+
| [Pinterest](https://developers.pinterest.com/docs/) | [link](https://developers.pinterest.com/apps/) | [link](https://www.pinterest.com/settings/security) | 2 ||| | || |
7172
| [Reddit](https://www.reddit.com/dev/api) | [link](https://www.reddit.com/prefs/apps/) | [link](https://www.reddit.com/settings/privacy) | 2 ||| ||||
7273
| [Slack](https://api.slack.com) | [link](https://api.slack.com/apps) | [link](https://slack.com/apps/manage) | 2 ||| | | | |
7374
| [SoundCloud](https://developers.soundcloud.com/) | [link](https://soundcloud.com/you/apps) | [link](https://soundcloud.com/settings/connections) | 2 || | ||| |

examples/get-token/Pinterest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @link https://developers.pinterest.com/docs/getting-started/authentication/
4+
*
5+
* @created 09.04.2024
6+
* @author smiley <smiley@chillerlan.net>
7+
* @copyright 2024 Smiley
8+
* @license MIT
9+
*/
10+
declare(strict_types=1);
11+
12+
use chillerlan\OAuth\Providers\Pinterest;
13+
14+
$ENVVAR ??= 'PINTEREST';
15+
16+
require_once __DIR__.'/../provider-example-common.php';
17+
18+
/** @var \OAuthExampleProviderFactory $factory */
19+
$provider = $factory->getProvider(Pinterest::class, $ENVVAR);
20+
21+
require_once __DIR__.'/_flow-oauth2.php';
22+
23+
exit;

src/Providers/Pinterest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Class PinterestAPITest
4+
*
5+
* @created 09.04.2024
6+
* @author smiley <smiley@chillerlan.net>
7+
* @copyright 2024 smiley
8+
* @license MIT
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace chillerlan\OAuthTest\Providers\Live;
13+
14+
use chillerlan\OAuth\Providers\Pinterest;
15+
use PHPUnit\Framework\Attributes\Group;
16+
17+
/**
18+
* @property \chillerlan\OAuth\Providers\Pinterest $provider
19+
*/
20+
#[Group('providerLiveTest')]
21+
class PinterestAPITest extends OAuth2ProviderLiveTestAbstract{
22+
23+
protected function getProviderFQCN():string{
24+
return Pinterest::class;
25+
}
26+
27+
protected function getEnvPrefix():string{
28+
return 'PINTEREST';
29+
}
30+
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Class PinterestTest
4+
*
5+
* @created 08.04.2024
6+
* @author smiley <smiley@chillerlan.net>
7+
* @copyright 2024 smiley
8+
* @license MIT
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace chillerlan\OAuthTest\Providers\Unit;
13+
14+
use chillerlan\OAuth\Providers\Pinterest;
15+
16+
/**
17+
* @property \chillerlan\OAuth\Providers\Pinterest $provider
18+
*/
19+
class PinterestTest extends OAuth2ProviderUnitTestAbstract{
20+
21+
protected function getProviderFQCN():string{
22+
return Pinterest::class;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)