Requirements
Prior to beginning, you should have:- A Twitch Account for testing.
- A Registered PlayFab title.
- Familiarity with Login basics and Best Practices.
- At the minimum, a server with a valid domain name to serve static HTML files.
Consult the Running an HTTP server for testing tutorial for information on how to set up a server with a valid domain name.
Server and domain
This tutorial requires a web server, in order to follow the instructions. If you don’t have a registered remote web server yet, follow our Running an HTTP server for testing tutorial, for information on how to run a local web server.Throughout this tutorial, we’ll assume your domain is
[http://localhost/](http://localhost/).Registering a Twitch application
Start by navigating to the Twitch website, and verifying that you’re logged in.- Navigate to the Account drop-down.
- Select Settings from the menu provided.
- Fill in the Name of the Application.
- Enter the Redirect URL.
- Enter the Application Category.
- Then agree to the Twitch terms, and select the Register button.
When testing using a local web server, Twitch allows you to use
**<http://localhost>** as a redirect URL. Make sure to include the leading slash /. Without a leading slash, Twitch will fail to recognize the localhost URL.Keep this Client ID in a safe and easily accessible place, as you’ll be using it later to configure your PlayFab title.
Configuring a PlayFab title
Once you acquire your Twitch Client ID, you can enable and configure a Twitch Add-on for your PlayFab title.- On your PlayFab Title screen, go to the menu and select the Add-ons item.
- Then select the Twitch icon link.
- A Settings page will open for the Twitch Add-on.
- Enter your Twitch Client ID.
- Select the Install Twitch button.
Testing
Use the following HTML file to test PlayFab authentication using Twitch. Make sure to replaceTWITCH_CLIENT_ID_GOES_HERE and PLAYFAB_TITLE_ID_GOES_HERE with your own values.
-
Request the following file from your server, using the domain you set up during the Twitch application configuration
<http://localhost>in our case. - Once the page opens, wait for the message indicating that the Twitch SDK was initialized.
- Then select the Login with Twitch button.
- Follow any Twitch instructions in the pop-up window, and watch the output.
If you already have a Twitch auth session going when reaching the page, it’s possible for callbacks to fire in a different, unexpected order. This case is shown in the screenshot shown below. However, you should make sure that only Logging in via PlayFab follows after Logged in with Twitch. This indicates that the token was received or restored from the local storage, and we don’t have to wait for the Twitch SDK to start signing in to PlayFab.
SessionTicket, you have successfully integrated Twitch authentication with your PlayFab app.