Authentication for matchmaker
Use authentication in Matchmaker to securely identify and authorize players.
読み終わるまでの所要時間 2 分最終更新 13時間前
There are two ways to authenticate in Matchmaker:
- Player authentication
- Service Account authentication
Player authentication
Player authentication uses Unity Authentication to enable player-driven matchmaking so that a game client can contact the Matchmaker service to create a ticket.
Make sure to initialize the Authentication service and sign in before making any calls using the Matchmaker SDK.
There are multiple ways to sign in. The simplest method is to use anonymous sign-in.
Multiplayer Services SDK implementation
In the Multiplayer Services SDK (), player authentication is a hard requirement, not an optional path. registers (from ) as a required dependency for the entire package, so the SDK can't initialize matchmaking without it.
com.unity.services.multiplayerMultiplayerInitializerIAccessTokenUnity.Services.Authentication.InternalEvery client-facing matchmaking call , , , , and internally calls a guard method ( in ) that checks . If the player hasn't signed in through the Authentication service, the call throws:
MatchmakeSessionAsyncCreateTicketAsyncGetTicketAsyncDeleteTicketAsyncGetMatchmakingResultsAsyncEnsureSignedIn()WrappedMatchmakerServiceIAccessToken.AccessTokenMatchmakerServiceException(Unauthorized, "You are not signed in to the Authentication Service. Please sign in.")
In practice, this means calling (or another sign-in method) before any matchmaking call, as shown in the SDK's own examples.
AuthenticationService.Instance.SignInAnonymouslyAsync()Service Account authentication
Use Service Account authentication when a backend service creates a matchmaking ticket on behalf of a game client. This is useful when it's 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's an example of a typical service-to-service authentication flow:
- The client performs an anonymous authentication as described in Player authentication.
- The client calls a custom backend server with the as the parameter.
PlayerId - The custom backend calls the ticket creation route with the header set to the
impersonate-user-idvalue:PlayerIdcurl --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}} } } ] }' - The custom backend sends the ticket ID back to the client.
- The client polls the ticket status using the client SDK.