-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d61fb64
commit 45085cd
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |