Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add provider for Spotify #229

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/Client/Provider/SpotifyClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* OAuth2 Client Bundle
* Copyright (c) KnpUniversity <http://knpuniversity.com/>
*
* 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();
}
}
2 changes: 2 additions & 0 deletions src/DependencyInjection/KnpUOAuth2ClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
77 changes: 77 additions & 0 deletions src/DependencyInjection/Providers/SpotifyProviderConfigurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* OAuth2 Client Bundle
* Copyright (c) KnpUniversity <http://knpuniversity.com/>
*
* 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';
}
}