Skip to main content
A PFEntityHandle is your primary credential for making PlayFab service calls. It represents an authenticated entity—either a player (title_player_account) or a title—and holds the entity token the SDK needs to authorize requests. Every login or authentication call returns a PFEntityHandle, and every service call requires one.

Getting an entity handle

You don’t create entity handles directly. Instead, you get one as an output of a successful login or authentication call. Player login (Windows example):
Title entity (server): Title entities authenticate with a secret key instead of a user credential. The returned PFEntityHandle works the same way, but it represents the title rather than a player. See Accessing PlayFab with a title entity for details.

Handle ownership and ref counting

PFEntityHandle is ref-counted. When you receive a handle from a login call, you own one reference. You can create additional references with PFEntityDuplicateHandle and release them with PFEntityCloseHandle. The underlying entity object is destroyed only when the last reference is closed. Rules:
  • Every call to a login GetResult function or PFEntityDuplicateHandle gives you a handle you must close.
  • Closing a handle doesn’t invalidate other handles to the same entity.
  • Close all handles before calling PFServicesUninitializeAsync.

Getting entity info

Entity key

The entity key identifies the entity (its type and ID). Use the two-call pattern: get the size first, then get the data.

Entity token

The entity token authorizes service calls. The SDK manages tokens automatically, but you can retrieve the current one if needed.

Checking entity type

Use PFEntityIsTitlePlayer as a quick check instead of inspecting the entity key type string:

Player entities vs. title entities

Both player and title entities use PFEntityHandle, but they differ in what they can do: Non-prefixed APIs (e.g., Inventory, Leaderboards, Data) can generally be called by both player and title entities unless otherwise noted in their documentation. Client-prefixed APIs are player-only, and Server-prefixed APIs are title-only. PFEntityGetSecretKey retrieves the secret key associated with a title entity. It fails for player entities because they don’t have one.
PFEntityGetSecretKey is only available on Windows, Linux, and macOS platforms.

Token event handlers

The SDK automatically refreshes entity tokens before they expire. You can register callbacks to observe these events.

Token expired

If automatic refresh fails (for example, the original login credential is no longer valid), the SDK fires the token-expired event. Register a handler to provide a new credential and retry the login.

Token refreshed

Register a token-refreshed handler if you want to know when the SDK successfully refreshes a token in the background. This is informational—you don’t need to take any action.

When to register and unregister

  • Register handlers early, right after SDK initialization and before login. This ensures you don’t miss any events.
  • Unregister handlers during shutdown, before you close entity handles.
For a complete walkthrough of token expiration handling and relogin, see Handling Token Expiration.

Utility accessors

You can retrieve the API endpoint and title ID from an entity handle. These come from the PFServiceConfigHandle that was used during login.

Complete example

This example demonstrates creating, duplicating, querying, and closing entity handles:

API reference

For the complete API reference, see PFEntity members.

See also

Last modified on August 10, 2026