Twitch auth provider

At this time, Arcade does not offer a default Twitch Auth Provider. To use Twitch auth, you must create a custom Auth Provider with your own Twitch OAuth 2.0 credentials as described below.

The Twitch auth provider enables tools and agents to call the Twitch API on behalf of a user. Behind the scenes, the Arcade Engine and the Twitch auth provider seamlessly manage Twitch OAuth 2.0 authorization for your users.

What’s documented here

This page describes how to use and configure Twitch auth with Arcade.

This auth provider is used by:

Configuring Twitch auth

In a production environment, you will most likely want to use your own Twitch app credentials. This way, your users will see your application’s name requesting permission.

You can use your own Twitch credentials in both the Arcade Cloud and in a self-hosted Arcade Engine instance.

Before showing how to configure your Twitch app credentials, let’s go through the steps to create a Twitch app.

Create a Twitch app

  • Twitch requires that you have two-factor authentication enabled for your account. Enable in your account security seetings
  • Create a Twitch Application in the Twitch App Console
  • Set the OAuth Redirect URL to: https://cloud.arcade.dev/api/v1/oauth/callback
  • Select your Application category
  • Select the ‘Confidential’ Client Type
  • Copy the App key (Client ID) and App secret (Client Secret), which you’ll need below

Next, add the Twitch app to your Arcade Engine configuration. You can do this in the Arcade Dashboard, or by editing the engine.yaml file directly (for a self-hosted instance).

Configuring your own Twitch Auth Provider in Arcade

There are two ways to configure your Twitch app credentials in Arcade:

  1. From the Arcade Dashboard GUI
  2. By editing the engine.yaml file directly (for a self-hosted Arcade Engine)

We show both options step-by-step below.

Configure Twitch Auth Using the Arcade Dashboard GUI

Access the Arcade Dashboard

To access the Arcade Cloud dashboard, go to api.arcade.dev/dashboard. If you are self-hosting, by default the dashboard will be available at http://localhost:9099/dashboard. Adjust the host and port number to match your environment.

  • Under the OAuth section of the Arcade Dashboard left-side menu, click Providers.
  • Click Add OAuth Provider in the top right corner.
  • Select the Included Providers tab at the top.
  • In the Provider dropdown, select Twitch.

Enter the provider details

  • Choose a unique ID for your provider (e.g. “my-twitch-provider”).
  • Optionally enter a Description.
  • Enter the Client ID and Client Secret from your Twitch app.

Create the provider

Hit the Create button and the provider will be ready to be used in the Arcade Engine.

When you use tools that require Twitch auth using your Arcade account credentials, the Arcade Engine will automatically use this Twitch OAuth provider. If you have multiple Twitch providers, see using multiple auth providers of the same type for more information.

Using Twitch auth in app code

Use the Twitch auth provider in your own agents and AI apps to get a user-scoped token for the Twitch API. See authorizing agents with Arcade to understand how this works.

Use client.auth.start() to get a user token for the Twitch API:

from arcadepy import Arcade
 
client = Arcade()  # Automatically finds the `ARCADE_API_KEY` env variable
 
user_id = "user@example.com"
 
# Start the authorization process
auth_response = client.auth.start(
    user_id=user_id,
    provider="twitch",
    scopes=["channel:manage:polls"],
)
 
if auth_response.status != "completed":
    print("Please complete the authorization challenge in your browser:")
    print(auth_response.url)
 
# Wait for the authorization to complete
auth_response = client.auth.wait_for_completion(auth_response)
 
token = auth_response.context.token
# Do something interesting with the token...

Using Twitch auth in custom tools

You can author your own custom tools that interact with the Twitch API.

Use the Twitch() auth class to specify that a tool requires authorization with Twitch. The context.authorization.token field will be automatically populated with the user’s Twitch token:

from typing import Annotated, Optional
 
import httpx
 
from arcade_tdk import ToolContext, tool
from arcade_tdk.auth import Twitch
 
 
@tool(
    requires_auth=Twitch(
        scopes=["channel:manage:polls"],
    )
)
async def create_poll(
    context: ToolContext,
    broadcaster_id: Annotated[
        str,
        "The ID of the broadcaster to create the poll for.",
    ],
    title: Annotated[
        str,
        "The title of the poll.",
    ],
    choices: Annotated[
        list[str],
        "The choices of the poll.",
    ],
    duration: Annotated[
        int,
        "The duration of the poll in seconds.",
    ],
) -> Annotated[dict, "The poll that was created"]:
    """Create a poll for a Twitch channel."""
    url = "https://api.twitch.tv/helix/polls"
    headers = {
        "Authorization": f"Bearer {context.authorization.token}",
        "Client-Id": "your_client_id",
        "Content-Type": "application/json",
    }
    payload = {
        "broadcaster_id": broadcaster_id,
        "title": title,
        "choices": [{"title": choice} for choice in choices],
        "duration": duration,
    }
 
    async with httpx.AsyncClient() as client:
        response = await client.post(url, headers=headers, json=payload)
        response.raise_for_status()
        return response.json()