Authentication

There are two ways to authenticate to Matchmaker:

  • Player Authentication
  • Service Account Authentication

Player authentication

Player authentication is used to enable player driven matchmaking, where a game client contacts directly the Matchmaker service to create a ticket. It uses Unity Authentication.

Make sure to initialize the authentication service and sign-in before making any call using the Matchmaker SDK.

There are multiple ways to sign-in, the most straight forward is anonymous sign-in.

Service Account authentication

Service Account authentication is used when a backend service creates a matchmaking ticket on behalf of a game client. This is useful when it is required to add server authoritative data to a matchmaking ticket like a skill value for example.

To create a Service Account follow these instructions.

To use the Service Account in Matchmaker, follow those steps.

Here is an example of a typical service-to-service authentication flow:

  1. The client performs an anonymous authentication as described above in Player authentication.

  2. The client calls a custom backend server with the PlayerId as the parameter

  3. The custom backend calls the ticket creation route with the impersonate-user-id header set to the PlayerId value:

    curl --location --request POST 'https://matchmaker.services.api.unity.com/v2/tickets' --header 'Content-Type: application/json' --header 'Authorization: {{SERVICE-ACCOUNT-TOKEN}}'
     --header 'impersonated-user-id: {{PLAYER-ID}}' --data-raw '{ "players": [ { "id": "{{PLAYER-ID}}", "customData": { "Skill": {{ENRICHED-DATA}} } } ] }'
  4. The custom backend sends the ticket id back to the client

  5. The client polls the ticket status using the client SDK