zairakai/laravel-twitch

Complete Twitch API integration package with OAuth, EventSub, badges system and event-driven architecture

Maintainers

Package info

gitlab.com/zairakai/php-packages/laravel-twitch

Issues

Documentation

pkg:composer/zairakai/laravel-twitch

Fund package maintenance!

Patreon

Other

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-03-11 19:56 UTC

This package is auto-updated.

Last update: 2026-03-11 19:02:53 UTC


README

Main Develop Coverage

GitLab Release Packagist Downloads License

PHP Laravel Static Analysis Code Style

Complete Twitch API integration for Laravel: OAuth, Helix API, EventSub webhooks, and a badges system.

Features

  • Helix API — games, streams, users, clips, channels, search, and more via Twitch facade
  • OAuth 2.0 — authorization code flow, token refresh, and PKCE support via TwitchOAuth facade
  • EventSub — subscribe to and handle Twitch webhook events with signature verification
  • Badges system — fetch, cache, and display global and channel emote/badge sets
  • Event-driven — Laravel events dispatched for every received EventSub notification
  • Token management — automatic token refresh and storage

Install

composer require zairakai/laravel-twitch

Publish the config:

php artisan vendor:publish --tag=config

Add your credentials to .env:

TWITCH_CLIENT_ID=your_client_id
TWITCH_CLIENT_SECRET=your_client_secret
TWITCH_REDIRECT_URI=https://your-app.com/auth/twitch/callback
TWITCH_WEBHOOK_SECRET=your_webhook_secret

Usage

Helix API

use Zairakai\LaravelTwitch\Facades\Twitch;

// Get top games
$games = Twitch::getTopGames();

// Get streams by user ID(s)
$streams = Twitch::getStreams(userIds: ['12345', '67890']);

// Get users by login(s) or ID(s)
$users = Twitch::getUsers(logins: 'username');

// Get the currently authenticated user (after setAccessToken)
$me = Twitch::getAuthenticatedUser();

// Search channels
$results = Twitch::searchChannels('gaming');

OAuth

use Zairakai\LaravelTwitch\Facades\TwitchOAuth;

// Redirect to Twitch authorization
$authUrl = TwitchOAuth::getAuthorizationUrl(['user:read:email', 'channel:read:subscriptions']);
return redirect($authUrl);

// Exchange code for token (in callback controller)
$token = TwitchOAuth::getAccessToken(request('code'));

// Refresh token
$newToken = TwitchOAuth::refreshToken($refreshToken);

EventSub

// Subscribe to events (webhook transport)
Twitch::createEventSubSubscription(
    type: 'stream.online',
    condition: ['broadcaster_user_id' => $broadcasterId],
    callbackUrl: route('twitch.webhook'),
    secret: config('twitch.eventsub.webhook_secret'),
);

// Handle webhooks — in routes/web.php
Route::post('/twitch/webhook', [TwitchAuthController::class, 'webhook']);

// Listen to dispatched Laravel events (string-based)
Event::listen('twitch.stream.online', function (array $eventData) {
    // handle the stream.online payload
});

Event::listen('twitch.channel.follow', function (array $eventData) {
    // handle the channel.follow payload
});

Configuration

Key options in config/twitch.php:

KeyDescription
client_idTwitch application client ID
client_secretTwitch application client secret
redirect_uriOAuth callback URL
webhook_secretSecret for EventSub signature verification
cache_ttlTTL in seconds for API response caching

Development

make quality        # pint + phpstan + rector + insights + markdownlint + shellcheck
make quality-fast   # pint + phpstan + markdownlint
make test           # phpunit / pest

Getting Help

License Security Policy Issues

Made with ❤️ by Zairakai