Back to Writing
NOTESazure-functionsplayfabauthenticationcsharp

Azure Functions with PlayFab - Authentication Token Setup

July 3, 2023Updated Feb 17, 2026

Using PlayFab;

// Initialize to use the PlayFab API.
// Set the project ID and developer secret key.
PlayFabSettings.staticSettings.TitleId = TITLE_ID;
PlayFabSettings.staticSettings.DeveloperSecretKey = DEVELOPERSECRET_KEY;

// Create the spec for authentication
PlayFab.AuthenticationModels.GetEntityTokenRequest request = new PlayFab.AuthenticationModels.GetEntityTokenRequest()
{
// *Bad example
Entity = new PlayFab.AuthenticationModels.EntityKey()
{
Id = id,
Type = type,
},
};

// Since there is no separate login on the server side,
// you need to get an authentication token like this and authenticate first.
var titleEntityResponse = await PlayFab.PlayFabAuthenticationAPI.GetEntityTokenAsync(request);

If you create the Request with an Entity object set like above, you will get a claim permission error.

So rather than initializing it separately:

Using PlayFab;

// Initialize to use the PlayFab API.
// Set the project ID and developer secret key.
PlayFabSettings.staticSettings.TitleId = TITLE_ID;
PlayFabSettings.staticSettings.DeveloperSecretKey = DEVELOPERSECRET_KEY;

// Create the spec for authentication
// * Good example
PlayFab.AuthenticationModels.GetEntityTokenRequest request = new PlayFab.AuthenticationModels.GetEntityTokenRequest();

// Since there is no separate login on the server side,
// you need to get an authentication token like this and authenticate first.
var titleEntityResponse = await PlayFab.PlayFabAuthenticationAPI.GetEntityTokenAsync(request);

For authentication to work, you must create the GetEntityTokenRequest object empty and use it immediately.