Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
efba920
refactor: Use Symfony HTTP Client instead of PSR
aaricdev Dec 22, 2022
9a81112
feat: Allow to set a static client_credential token
aaricdev Dec 28, 2022
26fc2a5
feat: Small fixes
aaricdev Feb 14, 2023
efae5df
feat: Update follow event
aaricdev Feb 22, 2023
1926f90
feat: Add auth type to condition
aaricdev Feb 22, 2023
ccba251
feat: Update array notation
aaricdev Feb 23, 2023
afc6983
fix: Add Serializer\Type to choice
aaricdev Feb 23, 2023
7ea00aa
fix: Fixed typo ...
aaricdev Feb 23, 2023
72ab691
fix: Fixed minor bugs, especially incompatibilities to Javas DateTime…
aaricdev Feb 25, 2023
e94915e
refactor: Use Symfony HTTP Client instead of PSR
aaricdev Dec 22, 2022
b9fff9b
feat: Allow to set a static client_credential token
aaricdev Dec 28, 2022
24bdb38
feat: Small fixes
aaricdev Feb 14, 2023
7251009
feat: Update follow event
aaricdev Feb 22, 2023
a6fe5d7
feat: Add auth type to condition
aaricdev Feb 22, 2023
e533c0f
feat: Update array notation
aaricdev Feb 23, 2023
230883f
fix: Add Serializer\Type to choice
aaricdev Feb 23, 2023
c554536
fix: Fixed typo ...
aaricdev Feb 23, 2023
55e5b4a
fix: Fixed minor bugs, especially incompatibilities to Javas DateTime…
aaricdev Feb 25, 2023
ea45a22
Merge remote-tracking branch 'origin/feature/implement-symfony-http-c…
aaricdev May 13, 2023
90eafd1
feat: Implement channel emote and badge endpoint
aaricdev May 14, 2023
c282de3
feat: Implemented new channel endpoints
aaricdev Jul 29, 2023
63aa411
feat: Update some APIs
aaricdev Jul 30, 2023
b449940
feat: Reflect most recent twitch api
aaricdev Oct 30, 2023
277b1f5
feat: Changed everything to objects
aaricdev Nov 3, 2023
91fdaab
feat: Moved parts of the EventSub to the new system
aaricdev Nov 7, 2023
0d43d11
feat: Current changes for new EventSub system
aaricdev Nov 9, 2023
05b4ca0
feat: Replaced http_build_query by a custom implementation
aaricdev Nov 11, 2023
1a80c5a
feat: Implemented test cases for every existing eventsub subscription…
aaricdev Nov 12, 2023
6a3168a
fix: Fixed class descriptions
aaricdev Nov 12, 2023
7bc5f62
feat: Implemented event DTOs
aaricdev Nov 14, 2023
e615623
feat: Implemented more tests for EventSubService.php
aaricdev Nov 14, 2023
ad72a9b
feat: Implemented more tests for EventSubService.php
aaricdev Nov 14, 2023
d878da9
feat: Set some test configuration values
aaricdev Nov 14, 2023
cfde383
feat: Move back from symfony client to psr-18 compatible version.
aaricdev Nov 17, 2023
68c4d13
refactor: Moved everything into a new repository to decouple from Sym…
aaricdev Nov 21, 2023
3e946c2
feat: Update README.md to mention, that this will now be a bridge for…
aaricdev Nov 21, 2023
eef65e6
refactor: Remove dead dependencies
aaricdev Dec 3, 2023
d8999ef
feat: Update dependencies
Jun 4, 2024
7e8bced
feat: Starting update for Symfony 7.4
Dec 29, 2025
131f7d9
feat: Remove .idea folder from repo. Updated twitchapi to dev-main (I…
Dec 29, 2025
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
25 changes: 25 additions & 0 deletions .github/workflows/test-lib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Test compatibility with symfony framework'

on:
pull_request:

jobs:
create-project:
name: Tests if project is usable
runs-on: Ubuntu-20.04

steps:
- name: Setup PHP 8.2
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "8.2"

- name: Create-project with skeleton ^6
run: |
set -x
php -v
composer create-project --ansi "symfony/skeleton:^6" v6
cd v6
composer config extra.symfony.allow-contrib true
composer require -W --ansi simply-stream/twitch-api-bundle:dev-${{ github.head_ref }}
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/TwitchApiBundle.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/php.xml

This file was deleted.

23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Twitch API Bundle

This library is a bridge between [SimplyStream/TwitchApi](https://github.com/Simply-Stream/TwitchApi) and [Symfony](https://symfony.com) and will initialize every API needed into a Symfony service.

Installation
============

Expand Down Expand Up @@ -42,23 +44,22 @@ return [
];
```

Configuration
Full configuration
=============

Following configuration is required:

```yaml
simplystream_twitch_api:
# Any \Psr\Http\Client\ClientInterface client implementation
http_client: 'psr18.http_client'
# Any \Psr\Http\Message\RequestFactoryInterface implementation
request_factory: 'nyholm.psr7.psr17_factory'
# Any \Psr\Http\Message\StreamFactoryInterface implementation
stream_factory: 'nyholm.psr7.psr17_factory'
# Currently the jms_serializer, but the intention is to support more
serializer: 'jms_serializer'
# Can set a static client_credential
token:
client_credentials:
token: '123'
expires_in: 1000
token_type: 'Bearer'
# See https://dev.twitch.tv/docs/authentication#registration on how to get client id and secret
twitch_id: '%env(TWITCH_ID)%'

# OAuth specific config

twitch_secret: '%env(TWITCH_SECRET)%'
# The url your user will be redirected to in authentication process
redirect_uri: '%env(TWITCH_REDIRECT_URI)%'
Expand Down
27 changes: 16 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
"authors": [
{
"name": "AaricDev",
"email": "support@simply-stream.com"
"email": "info@simply-stream.com"
}
],
"require": {
"php": "^8.2",
"symfony/http-foundation": "^6.2",
"league/oauth2-client": "^2.6",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"symfony/property-info": "^6.2",
"fproject/php-jwt": "^4.0"
"symfony/http-foundation": "^6.2 || ^7.0",
"symfony/property-info": "^6.2 || ^7.0",
"symfony/http-client": "^6.2 || ^7.0",
"nyholm/psr7": "^1.5",
"simply-stream/twitch-api": "dev-main"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"suggest": {
"nyholm/psr7": "An efficient implementation of response and stream factories"
"phpunit/phpunit": "^9.5",
"symfony/framework-bundle": "^6.2",
"symfony/yaml": "^6.3",
"phpstan/phpstan": "^1.10",
"php-http/mock-client": "^1.6"
},
"autoload": {
"psr-4": {
Expand All @@ -32,5 +32,10 @@
"psr-4": {
"SimplyStream\\TwitchApiBundle\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
16 changes: 15 additions & 1 deletion phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="./vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php">
<php>
<server name="APP_ENV" value="test" force="true"/>
<server name="KERNEL_CLASS" value="SimplyStream\TwitchApiBundle\Tests\AppTestKernel"/>
</php>

<testsuites>
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
36 changes: 15 additions & 21 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);

/*
* MIT License
Expand All @@ -13,38 +13,32 @@

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
public function getConfigTreeBuilder(): TreeBuilder {
$treeBuilder = new TreeBuilder('simplystream_twitch_api');
$rootNode = $treeBuilder->getRootNode();
//@formatter:off
$rootNode
->children()
->scalarNode('http_client')
->isRequired()
->info('Service id of HTTP client to use (must implement \Psr\Http\Client\ClientInterface)')
->end()
->scalarNode('serializer')
->isRequired()
->info('Service id of HTTP client to use (must implement \JMS\Serializer\SerializerInterface)')
->end()
->scalarNode('request_factory')
->isRequired()
->info('Service id of Request factory to use (must implement \Psr\Http\Message\RequestFactoryInterface)')
->end()
->scalarNode('stream_factory')
->isRequired()
->info('Service id of Request factory to use (must implement \Psr\Http\Message\StreamFactoryInterface)')
->arrayNode('token')
->children()
->arrayNode('client_credentials')
->children()
->scalarNode('token')->end()
->scalarNode('expires_in')->end()
->scalarNode('token_type')->end()
->end()
->end()
->end()
->end()
->scalarNode('twitch_id')->isRequired()->end()
->scalarNode('twitch_secret')->isRequired()->end()
->scalarNode('redirect_uri')->isRequired()->end()
->scalarNode('twitch_secret')->end()
->scalarNode('redirect_uri')->end()
->arrayNode('scopes')
->scalarPrototype()->end()
->end()
->arrayNode('webhook')
->children()
->scalarNode('secret')->isRequired()->end()
->scalarNode('secret')->end()
->end()
->end()
->end()
Expand Down
60 changes: 37 additions & 23 deletions src/DependencyInjection/SimplyStreamTwitchApiExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types = 1);
<?php
declare(strict_types=1);

/*
* MIT License
Expand All @@ -8,13 +9,10 @@

namespace SimplyStream\TwitchApiBundle\DependencyInjection;

use SimplyStream\TwitchApiBundle\Helix\Api\ApiClient;
use SimplyStream\TwitchApiBundle\Helix\EventSub\EventSubService;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class SimplyStreamTwitchApiExtension extends Extension
{
Expand All @@ -30,35 +28,51 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

// @TODO: Check if this class is still needed, now that KnpU has a helix provider
$twitchProviderDefinition = $container->getDefinition('simplystream_twitch_api.helix_authentication_provider.twitch_provider');
// This is deprecated and will be replaced by https://github.com/vertisan/oauth2-twitch-helix
$twitchProviderDefinition = $container->getDefinition(
'simplystream.twitch_api.helix_authentication_provider.twitch_provider'
);
$twitchProviderDefinition->setArgument(0, [
'clientId' => $config['twitch_id'],
'clientSecret' => $config['twitch_secret'],
'clientSecret' => $config['twitch_secret'] ?? null,
'urlAuthorize' => 'https://id.twitch.tv/oauth2/authorize',
'urlAccessToken' => 'https://id.twitch.tv/oauth2/token',
'urlResourceOwnerDetails' => 'https://id.twitch.tv/oauth2/userinfo',
'redirectUri' => $config['redirect_uri'],
'scopes' => $config['scopes'],
'redirectUri' => $config['redirect_uri'] ?? [],
'scopes' => $config['scopes'] ?? [],
]);

$eventServiceDefinition = $container->getDefinition(EventSubService::class);
$eventServiceDefinition->setArgument(3, [
$eventServiceDefinition = $container->getDefinition('simplystream.twitch_api.helix.event_sub_service');
$eventServiceDefinition->setArgument(2, [
'clientId' => $config['twitch_id'],
'webhook' => ['secret' => $config['webhook']['secret']],
'webhook' => ['secret' => $config['webhook']['secret'] ?? null],
]);

$apiClient = $container->register(
'simplystream_twitch_api.helix_api.api_client',
ApiClient::class
);
$apiClient->setArguments([
new Reference($config['http_client']),
new Reference($config['request_factory']),
$container->getDefinition('simplystream_twitch_api.helix_authentication_provider.twitch_provider'),
new Reference($config['serializer']),
new Reference($config['stream_factory']),
['clientId' => $config['twitch_id']],
$apiServiceDefinition = $container->getDefinition('simplystream.twitch_api.helix_api.api_client');
$apiServiceDefinition->setArgument(5, [
'clientId' => $config['twitch_id'],
'webhook' => ['secret' => $config['webhook']['secret'] ?? null],
]);
$container->setDefinition('simplystream.twitch_api.helix_api.api_client', $apiServiceDefinition);

$apiClientDefinition = $container->getDefinition('simplystream.twitch_api.helix_api.api_client');

$apiClientOptions = [
'clientId' => $config['twitch_id'],
];

if (isset($config['token']['client_credentials'])) {
$apiClientOptions['token'] = [
'client_credentials' => [
'token' => $config['token']['client_credentials']['token'],
'expires_in' => $config['token']['client_credentials']['expires_in'],
'token_type' => $config['token']['client_credentials']['token_type'],
],
];
}

$apiClientDefinition->setArgument('$options', [
'clientId' => $config['twitch_id']
]);
}

Expand Down
55 changes: 0 additions & 55 deletions src/Helix/Api/AbstractApi.php

This file was deleted.

Loading
Loading