Skip to content
Back to catalog
Twitch

OAuth with Twitch

Authenticate users with an existing Twitch account

Twitch is a live streaming platform for gaming, music, sports, and creative content. Developers build extensions, chat bots, and companion apps for Twitch streamers and viewers, and Twitch accounts work as an OAuth 2.0 sign-in for those apps.

How does the integration work?

You can use the Twitch OAuth adapter in Appwrite Auth for user authentication and management. This can be convenient for users because they can start using your app without creating a new account, and it suits stream tools, community sites, and games built for the Twitch audience.

Appwrite requests the user:read:email scope and reads the user's name and email address from the Twitch API. Twitch also shares the user's profile image, which Appwrite uses for user photos in Appwrite Avatars. Appwrite asks Twitch to show the authorization page on every sign-in, even when the user approved your app before.

Appwrite doesn't receive a verification status for the email address from the Twitch API, so it stores the address as unverified. If another user in your project already has the same address, Appwrite redirects to your failure URL instead of signing in to that account. To connect Twitch to an existing account, have the user sign in first and then start createOAuth2Session from the browser, which links Twitch as a new identity.

How to implement

To implement the Twitch OAuth adapter in Appwrite Auth, there are several steps you must complete:

Step 1: Register a Twitch application

First, sign in to the Twitch developer console. Twitch requires a verified email address and two-factor authentication on your account before you can register an application.

Open the Applications tab and click Register Your Application. Enter a unique Name and pick a Category. For OAuth Redirect URLs, temporarily add https://temporary-endpoint.com/. You will replace it with the URI from Appwrite in the next step. If the form asks for a client type, choose Confidential, since Appwrite exchanges the authorization code on the server with a client secret. Click Create.

Find your application under Developer Applications and click Manage. Save the Client ID, then click New Secret and save the client secret. Generating a new secret invalidates the previous one.

Step 2: Add the Twitch OAuth adapter to your Appwrite project

For this step, you must create an account on Appwrite Cloud or self-host Appwrite if you haven't already. In your Appwrite project, head over to the Auth page, open the Settings tab, and click Twitch under the OAuth2 Providers section.

Enter the Client ID and Client Secret you saved from Twitch, turn the provider on, and click Update.

Copy the Redirect URI shown in the provider settings. It follows this format:

Plain text
https://<REGION>.cloud.appwrite.io/v1/account/sessions/oauth2/callback/twitch/<PROJECT_ID>

The URI starts with the API endpoint your app uses, so on self-hosted Appwrite it starts with your own domain. Always copy the exact value from the Console. Back in the Twitch developer console, replace the temporary URL under OAuth Redirect URLs with this URI and save.

Step 3: Test the provider

Follow the OAuth 2 login flow to test your provider. Pass OAuthProvider.Twitch as the provider when you call createOAuth2Session from a client app or createOAuth2Token from a server. Add your app's domain as a platform in your Appwrite project so Appwrite accepts your success and failure URLs.

Read more about Twitch and Appwrite Auth

If you would like to learn more about Twitch and Appwrite Auth, we have some resources that you should visit:

Technology Partner Program

Building on Appwrite?

Teams and developers who ship integrations, tools, or services on Appwrite can join our partner program for verified catalog placement, co-marketing, training, and engineering support.