Skip to content

Kiankinakomochi/PlayfabMiniClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

PlayFab Mini Client

PlayFab Mini Client is a lightweight C# console application designed to help you test and develop PlayFab CloudScript using local Azure Functions. It sends HTTP requests to a locally hosted Azure Functions environment that consumes the PlayFab API, streamlining your local testing workflow before deploying to the cloud.

This tool is inspired by and built to complement the PlayFab Local Execution Example.


🚀 Features

  • Local CloudScript Execution: Directly invoke local Azure Functions mimicking PlayFab's ExecuteFunction endpoint.
  • Built-in PlayFab Authentication: Automatically handle authentication for both Title and Player (Custom ID) entities to generate X-EntityToken headers.
  • Gzip Compression: Easily test payload compression (--gzip-body and --accept-gzip).

⚙️ Installation & Setup

To use this script, you will need to set up a standard .NET Console Application environment.

  1. Install the .NET SDK: Ensure you have a recent .NET SDK installed.
  2. Create the Project: Open your terminal and create a new C# console application:
dotnet new console -n PlayFabMiniClient
cd PlayFabMiniClient
  1. Add Dependencies: Install the necessary NuGet packages required by the script (such as the PlayFab SDK):
dotnet add package PlayFabAllSDK
  1. Add the Code: Replace the default contents of Program.cs with your PlayFab Mini Client script.
  2. Build the Application: Compile the project to ensure there are no missing dependencies or syntax errors.
dotnet build

🛠 Usage

You can execute the application directly through the .NET CLI. To pass arguments to your console application rather than the dotnet tool itself, you must include -- before your commands.

The basic syntax is:

dotnet run -- [command] [options]

Commands

Command Description
execute (Default) Executes a local CloudScript/ExecuteFunction endpoint.
get-title-token Retrieves a Title Entity Token using your Title ID and Developer Secret Key.
login-custom-id Logs into the PlayFab Client API using a Custom ID and returns the entity token and key.
help, -h, --help Prints the help menu and lists all available options.

📖 Examples

1. Execute a local function (No Auth)

Invoke a local function named MyCustomFunction with an empty JSON payload.

dotnet run -- execute --function MyCustomFunction

2. Execute a local function (Player Auth)

Log in a player via Custom ID, generate their entity token, and pass it to the local function.

dotnet run -- execute \
  --function UpdatePlayerStats \
  --parameter-json "{\"score\": 100}" \
  --auth player-custom-id \
  --title-id 12345 \
  --custom-id "test_player_1"

3. Execute a local function (Title Auth)

Authenticate as the Title itself (requires the Dev Secret Key) and invoke the local function.

dotnet run -- execute \
  --function RunDailyServerTask \
  --auth title \
  --title-id 12345 \
  --dev-secret-key "YOUR_SECRET_KEY"

4. Execute a local function under a simulated player identity

If you want to simulate a specific player's request without logging in via Custom ID (e.g., testing edge cases for a known title_player_account), you can manually override the entity properties. This passes the exact identity context down to your local Azure Function.

dotnet run -- execute \
  --function GrantStartingInventory \
  --entity-token "YOUR_PLAYER_ENTITY_TOKEN" \
  --entity-id "A1B2C3D4E5F6" \
  --entity-type "title_player_account"

5. Run an automated test with assertions

Run a function and assert that it returns an HTTP 200 status code and a specific JSON response.

dotnet run -- execute \
  --function GetServerStatus \
  --expect-http-status 200 \
  --expect-function-result-json "{\"status\":\"online\"}"

6. Get a Title Token manually

Useful if you just need to generate a token to use in Postman or cURL.

dotnet run -- get-title-token --title-id 12345 --dev-secret-key "YOUR_SECRET_KEY"

⚙️ Options Reference

Common Execute Options

  • --function <name>: (Required) The name of the Azure Function to invoke.
  • --parameter-json <json>: The FunctionParameter JSON to send to the function. (Default: {})
  • --base-url <url>: The base URL of your local Azure Functions host. (Default: http://127.0.0.1:7071)
  • --route-prefix <prefix>: The route prefix used by your local host. (Default: api)
  • --auth <mode>: The authentication mode to use. Options: none, title, player-custom-id. (Default: none)
  • --output <path>: File path to write the raw response body.
  • --gzip-body: If flagged, gzips the request body and sets Content-Encoding: gzip.
  • --accept-gzip <true|false>: Sends the Accept-Encoding: gzip header. (Default: true)

PlayFab Authentication Options

  • --title-id <id>: Your PlayFab Title ID. Required for any PlayFab API calls or authentication.
  • --dev-secret-key <key>: Your PlayFab Secret Key. Required when using --auth title or the get-title-token command.
  • --custom-id <id>: A unique player string. Required when using --auth player-custom-id.
  • --create-account <true|false>: Whether to create a new PlayFab account if the Custom ID doesn't exist. (Default: true)
  • --cloud-name <name>: Optional PlayFab cloud segment for the host (e.g., <title>.<cloud>.playfabapi.com).

Manual Entity Overrides

If you already have a token and entity information, you can pass them directly instead of using the --auth modes:

  • --entity-token <token>: Explicitly set the X-EntityToken header.
  • --entity-id <id>: Explicitly set the ExecuteFunctionRequest.Entity.Id.
  • --entity-type <type>: Explicitly set the ExecuteFunctionRequest.Entity.Type.

Assertion Options

  • --expect-http-status <code>: Asserts the HTTP response status code. Returns a non-zero exit code if it fails. (Default: 200)
  • --expect-function-result-json <json>: Asserts that the data.FunctionResult deeply matches the provided JSON.

About

PlayFab Mini Client is a lightweight C# console application designed to help you test and develop PlayFab CloudScript using local Azure Functions. It sends HTTP requests to a locally hosted Azure Functions environment that consumes the PlayFab API, streamlining your local testing workflow before deploying to the cloud.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages