Skip to content

Commit

Permalink
Twitch helix support (#361)
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Bocharsky <bocharsky.bw@gmail.com>
  • Loading branch information
ErdemUyanik and bocharsky-bw authored Feb 22, 2022
1 parent 4b7beca commit ed13752
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 2 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ via Composer:
| [SymfonyConnect](https://github.com/qdequippe/oauth2-symfony-connect) | composer require qdequippe/oauth2-symfony-connect |
| [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 |
| [Twitch](https://github.com/tpavlek/oauth2-twitch) | composer require depotwarehouse/oauth2-twitch |
| [Twitch Deprecated](https://github.com/tpavlek/oauth2-twitch) | composer require depotwarehouse/oauth2-twitch |
| [Twitch Helix](https://github.com/vertisan/oauth2-twitch-helix) | composer require vertisan/oauth2-twitch-helix |
| [Uber](https://github.com/stevenmaguire/oauth2-uber) | composer require stevenmaguire/oauth2-uber |
| [Unsplash](https://github.com/hughbertd/oauth2-unsplash) | composer require hughbertd/oauth2-unsplash |
| [Vimeo](https://github.com/saf33r/oauth2-vimeo) | composer require saf33r/oauth2-vimeo |
Expand Down Expand Up @@ -1414,6 +1415,21 @@ knpu_oauth2_client:
# whether to check OAuth2 "state": defaults to true
# use_state: true

# will create service: "knpu.oauth2.client.twitch_helix"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\TwitchHelixClient
# composer require vertisan/oauth2-twitch-helix
twitch_helix:
# must be "twitch_helix" - it activates that type!
type: twitch_helix
# add and set these environment variables in your .env files
client_id: '%env(OAUTH_TWITCH_HELIX_CLIENT_ID)%'
client_secret: '%env(OAUTH_TWITCH_HELIX_CLIENT_SECRET)%'
# a route name you'll create
redirect_route: connect_twitch_helix_check
redirect_params: {}
# whether to check OAuth2 "state": defaults to true
# use_state: true

# will create service: "knpu.oauth2.client.uber"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\UberClient
# composer require stevenmaguire/oauth2-uber
Expand Down
34 changes: 34 additions & 0 deletions src/Client/Provider/TwitchHelixClient.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\Token\AccessToken;
use Vertisan\OAuth2\Client\Provider\TwitchHelixResourceOwner;

class TwitchHelixClient extends OAuth2Client
{
/**
* @return TwitchHelixResourceOwner|\League\OAuth2\Client\Provider\ResourceOwnerInterface
*/
public function fetchUserFromToken(AccessToken $accessToken)
{
return parent::fetchUserFromToken($accessToken);
}

/**
* @return TwitchHelixResourceOwner|\League\OAuth2\Client\Provider\ResourceOwnerInterface
*/
public function fetchUser()
{
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 @@ -60,6 +60,7 @@
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\StravaProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\StripeProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\SymfonyConnectProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\TwitchHelixProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\TwitchProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\UberProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\UnsplashProviderConfigurator;
Expand Down Expand Up @@ -141,6 +142,7 @@ class KnpUOAuth2ClientExtension extends Extension
'strava' => StravaProviderConfigurator::class,
'stripe' => StripeProviderConfigurator::class,
'twitch' => TwitchProviderConfigurator::class,
'twitch_helix' => TwitchHelixProviderConfigurator::class,
'uber' => UberProviderConfigurator::class,
'unsplash' => UnsplashProviderConfigurator::class,
'vimeo' => VimeoProviderConfigurator::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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 KnpU\OAuth2ClientBundle\Client\Provider\TwitchHelixClient;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Vertisan\OAuth2\Client\Provider\TwitchHelix;

/**
* @Author Erdem Uyanik
*/
class TwitchHelixProviderConfigurator implements ProviderConfiguratorInterface
{
public function buildConfiguration(NodeBuilder $node)
{
// no custom options
}

public function getProviderClass(array $config)
{
return TwitchHelix::class;
}

public function getProviderOptions(array $config)
{
return [
'clientId' => $config['client_id'],
'clientSecret' => $config['client_secret'],
];
}

public function getPackagistName()
{
return 'vertisan/oauth2-twitch-helix';
}

public function getLibraryHomepage()
{
return 'https://github.com/vertisan/oauth2-twitch-helix';
}

public function getProviderDisplayName()
{
return 'Twitch Helix';
}

public function getClientClass(array $config)
{
return TwitchHelixClient::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getLibraryHomepage()

public function getProviderDisplayName()
{
return 'Twitch';
return 'Twitch Deprecated';
}

public function getClientClass(array $config)
Expand Down

0 comments on commit ed13752

Please sign in to comment.