Skip to main content

Set up Twitch as an identity provider

Last updated on October 24, 2024

Overview

This guide is intended to help verified Twitch developers to connect Twitch Accounts to AccelByte Gaming Services (AGS). You may need to set up additional features within Twitch services which are not listed here. For full information about setting up Twitch services, we recommend contacting your Twitch representative and reviewing Twitch documentation directly.

important

This guide is intended for public use and contains limited information due to confidentiality. We recommend you refer to the full confidential guide first. Contact your AccelByte Technical Producer to request a copy of the guide.

Goals

  • Enable the Twitch authentication method for your game with the AccelByte Game SDK.
  • Enable the Twitch authentication method for your publisher website with the AccelByte Player Portal.

Prerequisites

Web Login Integration

  • You must have an Verified Twitch Account and Developer Twitch Access.
  • An AccelByte Admin Portal Account to set up authentication and manage permissions.
  • A publisher Namespace for your Player Portal and Launcher.
  • A Player Portal.

In-game login integration

  • You must have an Verified Twitch Account and Developer Twitch Access.
  • An AccelByte Admin Portal Account to set up authentication and manage permissions.
  • A game Namespace.
  • A Unity or Unreal game project with the latest version of the AccelByte Game SDK imported.
  • Familiarity with AGS Identity and Access Management (IAM) Clients.

Setting up Twitch App

Set Up Twitch Developer Organizations (optional)

Set up Twitch Developer Organizations. Follow the Registering and Managing Organizations Guide

Enable Twitch 2FA

Enable 2FA for your Twitch Account. Follow the Setting up Two-Factor Authentication Guide

Register Application

Register Application on your Twitch Developer Console. Follow the Registering Your App Guide

note

Please contact Customer Support to get the guide from AccelByte if you have trouble setting up on Twitch Developer Console.

Set up Twitch login method

Web Login

Use the following steps to set up Twitch logins in the player portal. This will allow your players to sign in to your player portal using their Twitch accounts.

  1. In the AGS Admin portal, go to your publisher namespace.

  2. On the sidebar menu, go to Game Setup > 3rd Party Configuration > Auth & Account Linking.

  3. On the Login Methods page, click on the + Add New button.

    AccelByte Admin Portal Login

  4. From the list of login method options, select Twitch.

    Twitch

  5. Fill the login configuration with your Twitch App credentials. Fill Client ID with your twitch clientID, Client Secret with your twitch client secret and Fill Redirect URI with Your Twitch Login Redirect URI: <BaseURL\>/iam/v3/platforms/twitch/authenticate (BaseURL is your domain address, e.g., https://development.accelbyte.io).

    Twitch Create Configuration

  6. You will redirect to the detail page, at this point you just need to activate it and it will able to be used.

    Activate Twitch

Give it a try

Make sure you have already set up the Twitch login method in your publisher namespace.

  1. Go to your Player Portal and click on Login.

    AccelByte Player Portal

  2. Click on Twitch. If you can't find it icon, you can click More login options and click Login with Twitch.

    AccelByte Player Portal Login

  3. Login with your Twitch account credential.

    Twitch Login

note

Currently, players will be asked to link their Twitch account with an existing AccelByte account or link it with a new account. There is an effort underway at AccelByte to make this configurable so that players can login to the Player Portal directly with a headless account.

In-game login

  1. In the AGS Admin portal, go to your game namespace.

  2. On the sidebar menu, go to Game Setup > 3rd Party Configuration > Auth & Account Linking.

  3. On the Login Methods page, click on the + Add New button.

    AccelByte Admin Portal Login

  4. From the list of login method options, select Twitch.

    Twitch

  5. Fill the login configuration with your Twitch App credentials. Fill Client ID with your twitch clientID, Client Secret with your twitch client secret and Fill Redirect URI with Your BaseURL Domain (BaseURL is your domain address, e.g., https://development.accelbyte.io).

    Twitch Create Configuration

  6. You will redirect to the detail page, at this point you just need to activate it and it will able to be used.

    Activate Twitch

Create an IAM client for Twitch

An IAM client is a representation of the game client that you want to release on your target platform.

If you already have an IAM Client for your game on a specific SDK Platform (e.g., Xbox, Steam, or Playstation), you don't have to create a new IAM Client. Since Twitch is not a platform on which to build games, you can use an existing IAM Client. To learn more about IAM Clients, see the Manage Access control for applications article.

In-game login integration

The setup for each game engine is different. Please choose your game engine from the available tabs.

Unreal Engine In-game login integration

Unreal Preparation and Configuration

Adding dependency

First you need to add public dependency modules called AccelbyteUe4Sdk, This dependencies needed for integrating your project to use the our AccelByte SDK Plugin within Unreal Engine.

public ABThirdPartyLogin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "AccelByteUe4Sdk", "Slate", "SlateCore" });

PrivateDependencyModuleNames.AddRange(new string[] { "Json", "HTTP" });

}

Add AccelbyteUe4Sdk inside <YourProject>.Target.cs and <YourProjectEditor>.Target.cs

public ABThirdPartyLoginTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "ABThirdPartyLogin", "AccelByteUe4Sdk" } );
}
public ABThirdPartyLoginEditorTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "ABThirdPartyLogin", "AccelByteUe4Sdk" } );
}

Unreal Engine Project Setting for Twitch Login

Inside your DefaultEngine.ini file please Add AccelByte credential here on DefaultEngine.ini

[/Script/AccelByteUe4Sdk.AccelByteSettings]
ClientId=<Your Client_Id>
ClientSecret=<Your Client_Secret>
Namespace=<Your Namespace>
PublisherNamespace=<Your Publisher Namespace>
RedirectURI="http://127.0.0.1"
BaseUrl="https://prod.gamingservices.accelbyte.io"
IamServerUrl="https://prod.gamingservices.accelbyte.io/iam"
PlatformServerUrl="https://prod.gamingservices.accelbyte.io/platform"

Unreal Sample Code Implementation

Next step, we will show you how to implement the Twitch authentication method for your game with sample code below.

  1. Create WebBrowser item in BluePrint as a login container.
  2. Load Login Twitch Url and add auth params :
    1. redirect_uri: RedirectURL when login is done. Since redirection is back to the game fill value with BaseURL (FRegistry::Settings.BaseUrl). Also, put the BaseUrl value in the Redirect Uri config in the Twitch developer portal to whitelist.
    2. response_type: Put value with "code".
    3. scope: Put value with permission scope.
void UAccelByteAuth::TwitchLogin()
{
FString TwitchClientId;
GConfig->GetString(TEXT("TwitchClientId"), TwitchClientId, GEngineIni);
FString RedirectUri = TEXT("YOUR_TWITCH_REDIRECTURI");
FString Scope = TEXT("user:read:email");

FString Url = FString::Printf(TEXT("https://your_domain?client_id=%s&redirect_uri=%s&response_type=%s&scope=%s"),
*FGenericPlatformHttp::UrlEncode(TwitchClientId),
*FGenericPlatformHttp::UrlEncode(RedirectUri),
TEXT("code"),
*FGenericPlatformHttp::UrlEncode(Scope));

WBrowser_LoginAuth->LoadURL(Url);
WBrowser_LoginAuth->OnUrlChanged.AddUniqueDynamic(this, &UAccelByteAuth::AccelByteLoginWithTwitch);
}
void UAccelByteAuth::AccelByteLoginWithTwitch(const FText& NewUrl)
{
FString Url = NewUrl.ToString();
FString RedirectUri = FRegistry::Settings.BaseUrl;
FString LoginCode = TEXT("");

if (Url.Contains(RedirectUri))
{
LoginCode = FGenericPlatformHttp::GetUrlParameter(Url, TEXT("code")).GetValue();
}

if (!LoginCode.IsEmpty())
{
FRegistry::User.LoginWithOtherPlatform(AccelByte.Models.PlatformType.Twitch, LoginCode, FVoidHandler::CreateWeakLambda(this, [this]()
{
// Handle Success Login
}),
FCustomErrorHandler::CreateWeakLambda(this, [](int32 ErrorCode, const FString& ErrorMessage, const FJsonObject& ErrorJson)
{
// Handle Error Login
}));

// Close Login Page (Hide WebBrowser)
}
}
note

platform_token for Twitch Authentication is Auth/Login Code

After adding this sample code to your project, compile your project, then build and run your project. That's it!

Sample Code Testing

Below we post a screenshot demonstrating that the code works and we are able to login using Twitch with the sample code. Unreal Code Testing