diff --git a/README.md b/README.md index 92af938a..01603a7b 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ via Composer: | [PSN](https://github.com/larabros/oauth2-psn) | composer require larabros/oauth2-psn | | [Salesforce](https://github.com/stevenmaguire/oauth2-salesforce) | composer require stevenmaguire/oauth2-salesforce | | [Slack](https://github.com/adam-paterson/oauth2-slack) | composer require adam-paterson/oauth2-slack | +| [Spotify](https://github.com/ker0x/oauth2-spotify) | composer require kerox/oauth2-spotify | | [Strava](https://github.com/Edwin-Luijten/oauth2-strava) | composer require edwin-luijten/oauth2-strava | | [Stripe](https://github.com/adam-paterson/oauth2-stripe) | composer require adam-paterson/oauth2-stripe | | [Uber](https://github.com/stevenmaguire/oauth2-uber) | composer require stevenmaguire/oauth2-uber | @@ -1119,6 +1120,21 @@ knpu_oauth2_client: # whether to check OAuth2 "state": defaults to true # use_state: true + # will create service: "knpu.oauth2.client.spotify" + # an instance of: KnpU\OAuth2ClientBundle\Client\Provider\SpotifyClient + # composer require kerox/oauth2-spotify + spotify: + # must be "spotify" - it activates that type! + type: spotify + # add and set these environment variables in your .env files + client_id: '%env(OAUTH_SPOTIFY_CLIENT_ID)%' + client_secret: '%env(OAUTH_SPOTIFY_CLIENT_SECRET)%' + # a route name you'll create + redirect_route: connect_spotify_check + redirect_params: {} + # whether to check OAuth2 "state": defaults to true + # use_state: true + # will create service: "knpu.oauth2.client.strava" # an instance of: KnpU\OAuth2ClientBundle\Client\Provider\StravaClient # composer require edwin-luijten/oauth2-strava diff --git a/src/Client/Provider/SpotifyClient.php b/src/Client/Provider/SpotifyClient.php new file mode 100644 index 00000000..237bbbf5 --- /dev/null +++ b/src/Client/Provider/SpotifyClient.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace KnpU\OAuth2ClientBundle\Client\Provider; + +use KnpU\OAuth2ClientBundle\Client\OAuth2Client; +use League\OAuth2\Client\Provider\ResourceOwnerInterface; +use League\OAuth2\Client\Token\AccessToken; + +class SpotifyClient extends OAuth2Client +{ + /** + * @return \Kerox\OAuth2\Client\Provider\SpotifyResourceOwner|\League\OAuth2\Client\Provider\ResourceOwnerInterface + */ + public function fetchUserFromToken(AccessToken $accessToken): ResourceOwnerInterface + { + return parent::fetchUserFromToken($accessToken); + } + + /** + * @return \Kerox\OAuth2\Client\Provider\SpotifyResourceOwner|\League\OAuth2\Client\Provider\ResourceOwnerInterface + */ + public function fetchUser(): ResourceOwnerInterface + { + return parent::fetchUser(); + } +} diff --git a/src/DependencyInjection/KnpUOAuth2ClientExtension.php b/src/DependencyInjection/KnpUOAuth2ClientExtension.php index 1d66d610..f2bf49b7 100644 --- a/src/DependencyInjection/KnpUOAuth2ClientExtension.php +++ b/src/DependencyInjection/KnpUOAuth2ClientExtension.php @@ -53,6 +53,7 @@ use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\PsnProviderConfigurator; use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\SalesforceProviderConfigurator; use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\SlackProviderConfigurator; +use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\SpotifyProviderConfigurator; use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\StravaProviderConfigurator; use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\StripeProviderConfigurator; use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\UberProviderConfigurator; @@ -126,6 +127,7 @@ class KnpUOAuth2ClientExtension extends Extension 'psn' => PsnProviderConfigurator::class, 'salesforce' => SalesforceProviderConfigurator::class, 'slack' => SlackProviderConfigurator::class, + 'spotify' => SpotifyProviderConfigurator::class, 'strava' => StravaProviderConfigurator::class, 'stripe' => StripeProviderConfigurator::class, 'uber' => UberProviderConfigurator::class, diff --git a/src/DependencyInjection/Providers/SpotifyProviderConfigurator.php b/src/DependencyInjection/Providers/SpotifyProviderConfigurator.php new file mode 100644 index 00000000..7cf16ab1 --- /dev/null +++ b/src/DependencyInjection/Providers/SpotifyProviderConfigurator.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace KnpU\OAuth2ClientBundle\DependencyInjection\Providers; + +use Kerox\OAuth2\Client\Provider\Spotify; +use KnpU\OAuth2ClientBundle\Client\Provider\SpotifyClient; +use Symfony\Component\Config\Definition\Builder\NodeBuilder; + +class SpotifyProviderConfigurator implements ProviderConfiguratorInterface +{ + /** + * {@inheritdoc} + */ + public function buildConfiguration(NodeBuilder $node): void + { + // no custom options + } + + /** + * {@inheritdoc} + */ + public function getProviderClass(array $configuration): string + { + return Spotify::class; + } + + /** + * {@inheritdoc} + */ + public function getClientClass(array $config): string + { + return SpotifyClient::class; + } + + /** + * {@inheritdoc} + */ + public function getProviderOptions(array $configuration): array + { + return [ + 'clientId' => $configuration['client_id'], + 'clientSecret' => $configuration['client_secret'], + ]; + } + + /** + * {@inheritdoc} + */ + public function getPackagistName(): string + { + return 'kerox/oauth2-spotify'; + } + + /** + * {@inheritdoc} + */ + public function getLibraryHomepage(): string + { + return 'https://github.com/ker0x/oauth2-spotify'; + } + + /** + * {@inheritdoc} + */ + public function getProviderDisplayName(): string + { + return 'Spotify'; + } +}