メインコンテンツまでスキップ

イベントハンドラの使用を開始する

Last updated on June 12, 2025

Overview

This article walks you through how to set up an Extend Event Handler app. For this purpose, the Extend Event Handler app template is used. It listens to the AccelByte Gaming Services (AGS) UserLogin event and grants in-game entitlement when a user logs in.

Prerequisites

  1. Windows 11 WSL2/Linux Ubuntu 22.04 or macOS 14+ with the following tools installed:

    a. Bash

    • On Windows WSL2 or Linux Ubuntu:

      bash --version

      GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
      ...
    • On macOS:

      bash --version

      GNU bash, version 3.2.57(1)-release (arm64-apple-darwin23)
      ...

    b. Make

    • On Windows WSL2 or Linux Ubuntu:

      To install from the Ubuntu repository, run sudo apt update && sudo apt install make.

      make --version

      GNU Make 4.3
      ...
    • On macOS:

      make --version

      GNU Make 3.81
      ...

    c. Docker (Docker Desktop 4.30+/Docker Engine v23.0+)

    • On Linux Ubuntu:

      1. To install from the Ubuntu repository, run sudo apt update && sudo apt install docker.io docker-buildx docker-compose-v2.
      2. Add your user to the docker group: sudo usermod -aG docker $USER.
      3. Log out and log back in to allow the changes to take effect.
    • On Windows or macOS:

      Follow Docker's documentation on installing the Docker Desktop on Windows or macOS.

      docker version

      ...
      Server: Docker Desktop
      Engine:
      Version: 24.0.5
      ...

    d. .NET 6 SDK

    • On Linux Ubuntu:

      To install from the Ubuntu repository, run sudo apt-get update && sudo apt-get install -y dotnet-sdk-6.0.

    • On Windows or macOS:

      Follow Microsoft's documentation for installing .NET on Windows or on macOS.

      dotnet --version

      6.0.128

    e. Postman

    • Use binary available here

    f. extend-helper-cli

    • Use binary available here
  1. Access to the AGS Admin Portal environment.

    • Base URL: <your environment's domain URL>
      • Example for AGS Shared Cloud customer: https://spaceshooter.prod.gamingservices.accelbyte.io
      • Example for AGS Private Cloud customer: https://dev.customer.accelbyte.io
    • Create a game namespace if you don't have one yet. Take note of the namespace ID.
    • Create an OAuth Client with confidential client type containing the following permissions:
      • For AGS Private Cloud customers:
        • ADMIN:NAMESPACE:{namespace}:USER:*:FULFILLMENT [CREATE]
      • For AGS Shared Cloud customers:
        • Platform Store -> Fulfillment (Create) Keep the Client ID and Client Secret.
  2. Set up the store and the item to grant.

    1. Create and publish a new store in your namespace. You can also use your existing store if any. For more details about creating and publishing stores, see Store and Entitlements.

      Store in AGS Admin Portal

    2. After you have created and published your store, take a note of the Item ID in the published store you want to grant when a user logs in.

      Published Item in AGS Admin Portal

Clone the app template

git clone https://github.com/AccelByte/extend-event-handler-csharp.git

Set up, run, and test an Extend app

This section covers how to set up, build, run, and then test an Extend app.

Set up the Extend app

To be able to run this app, follow these setup steps:

  1. Create a docker compose .env file by copying the content of the .env.template file.

    注記

    The host OS environment variables have higher precedence compared to the .env file variables. If the variables in the .env file do not seem to take effect properly, check if there are host OS environment variables with the same name. For more details, refer to Docker's documentation about the docker compose environment variables precedence.

  2. Fill in the required environment variables in the .env file as shown below:.

    AB_BASE_URL=https://test.accelbyte.io     # Base URL of AGS environment
    AB_CLIENT_ID='xxxxxxxxxx' # Client ID from the Prerequisites section
    AB_CLIENT_SECRET='xxxxxxxxxx' # Client Secret from the Prerequisites section
    AB_NAMESPACE='xxxxxxxxxx' # Namespace ID from the Prerequisites section

Build the Extend app

To build this app, run the following command:

make build

Run the Extend app

To (build and) run this app in a container, run the following command:

docker compose up --build

Test the Extend app

This app can be tested locally using Postman.

  1. Run this app by using the command below.

    docker compose up --build
  2. Open Postman, create a new gRPC request, and enter localhost:6565 as the URL.

    Postman new grpc request

  3. Since we are interested in UserLogin event, select UserAuthenticationUserLoggedInService/OnMessage method.

    Postman new grpc request

  4. Send a UserLogin event to the gRPC server by copying and pasting the sample Kafka event JSON below, then click Invoke. For the sample provided in this Extend app template, ensure that you provide valid values for at least namespace and userId.

    {
    "payload": {
    "userAccount": {
    "userId": "string",
    "emailAddress": "string",
    "country": "string",
    "namespace": "string"
    },
    "userAuthentication": {
    "platformId": "string",
    "refresh": true
    }
    },
    "id": "string",
    "version": 0,
    "name": "string",
    "namespace": "string",
    "parentNamespace": "string",
    "timestamp": "2019-08-24T14:15:22Z",
    "clientId": "string",
    "userId": "string",
    "traceId": "string",
    "sessionId": "string"
    }
  5. If successful, the response will appear as shown below, and you will also be able to see the item granted to the user you are using for this test.

    Postman new grpc request

    Granted entitlement

Deploy in AGS

Create the Extend app

  1. In the AGS Admin Portal, go to the namespace where wish to create your Extend Event Handler app.

  2. On the sidebar menu, hover over Extend and click Event Handler. Click Create New to create a new Extend Event Handler app.

  3. On the app creation page, type in the App Name and the Description. You can adjust the resources setting if necessary. Then, click Create.

Upload the Extend app

  1. Set up an IAM client for extend-helper-cli. Create an IAM client with client type confidential and assign the required permissions listed below. Keep a copy of the Client ID and Client Secret.

    • For AGS Private Cloud customers:
      • ADMIN:NAMESPACE:{namespace}:EXTEND:REPOCREDENTIALS [READ]
      • ADMIN:NAMESPACE:{namespace}:EXTEND:APP [READ]
    • For AGS Shared Cloud customers:
      • Extend > Extend app image repository access (Read)
      • Extend > App (Read)
  2. Export the required environment variables, then build and upload the Extend app container image to AGS using extend-helper-cli.

    • Ensure <project-dir> points to your Extend app project directory
    • The values for <namespace> and <app-name> can be found on the App Detail page of your Extend app
    • Use an appropriate image tag e.g. v0.0.1
    # Your AGS environment base URL, e.g., https://spaceshooter.prod.gamingservices.accelbyte.io, https://dev.accelbyte.io, etc.
    export AB_BASE_URL='https://xxxxxxxxxx'
    # Client ID of OAuth Client for extend-helper-cli (from step 1)
    export AB_CLIENT_ID='xxxxxxxxxx'
    # Client Secret of OAuth Client for extend-helper-cli (from step 1)
    export AB_CLIENT_SECRET='xxxxxxxxxx'

    ./extend-helper-cli-linux_amd64 image-upload --login --work-dir <project-dir> --namespace <namespace> --app <app-name> --image-tag v0.0.1
    備考
    • We recommend running the above commands in a separate terminal and from a different working directory than the Extend app project. This helps prevent the extend-helper-cli from inadvertently using environment variables intended for the Extend app.
    • If you encounter the following error, see Troubleshooting: Docker login fails for resolution steps.
      Error saving credentials: error storing credentials - err: exit status 1, out: `error storing credentials - err: exit status 1, out: `The stub received bad data.`

    If your images are successfully uploaded, you will see an image with version v0.0.1 on the Image Version History page.

    image history in AGS Admin Portal

Configure the Extend app

Before deploying the Extend app that you uploaded, you must configure the environment variables required by the Extend app. In the app's details page, set the following environment variables with the same values that you used to run and test the Extend app locally.

  • AB_CLIENT_ID
  • AB_CLIENT_SECRET
  • ITEM_ID_TO_GRANT

Deploy the Extend app

To deploy the Extend app, click Deploy Latest Image. Wait until the app status updates to RUNNING, which indicates that your Extend app is successfully deployed.

Test the deployed Extend app

Create a new user in your namespace and login using that user. Check if the Item ID has been granted in that user's entitlement page in Admin Portal.

Granted entitlement

Next steps