Search Unity

Resolved Service Account can't update Lobby Data

Discussion in 'Lobby' started by BSimonSweet, Jan 10, 2024.

  1. BSimonSweet

    BSimonSweet

    Joined:
    Aug 17, 2022
    Posts:
    67
    Edit : the bug was on my side :) Nothing happened here ...

    Hi !

    I'm trying to update a Lobby custom data with a Service Account, but I get an error stating that only the host of the Lobby can do that.

    The Lobby is created from a connected player, and on my game server I need to update custom data from that Lobby. On my server, I use a Service Account for API call, but when trying to update Lobby custom data it doesn't work ...

    The Service Account has the right role to call this API (https://services.docs.unity.com/lobby/v1/#tag/Lobby/operation/updateLobby).
     
    Last edited: Jan 11, 2024
  2. mcanfield_unity

    mcanfield_unity

    Unity Technologies

    Joined:
    Mar 1, 2022
    Posts:
    13
    Hi there @BSimonSweet , I noticed this has been marked resolved. Mind sharing what the implementation mistake was?

    For future forum browsers also be aware that there are some features of authentication available to you to accomplish various architectures.

    Firstly, there is a Bulk Update api that can be used as the heavy hammer for a Service Account to update the Lobby: https://services.docs.unity.com/lobby/v1/#tag/Lobby/operation/bulkUpdateLobby

    Also, you can impersonate a user if needed with the
    impersonated-user-id
    header on the api endpoint you are trying to call. Though you probably should only do that for actions you'd normally expect a user to be taking.

    Finally, if you are using the Unity dedicated game servers (Multiplay) there is a token available to you within that server context which might be useful- https://docs.unity.com/ugs/en-us/ma...using_a_Game_Server_Hosting_(Multiplay)_token


    // You can retrieve a Game Server Hosting (Multiplay) token by running the following request on the game server:
    curl -X GET http://localhost:8086/v4/token

    //The request would return a response in the format below:

    {"token":"<BEARER_TOKEN>", "error":""}
     
  3. BSimonSweet

    BSimonSweet

    Joined:
    Aug 17, 2022
    Posts:
    67
    Hi ! The mistake was on the method I implemented to perform a Lobby Data Update request, nothing related to the API or the SDK itself. I have a condition before performing the request that was checking the local player ID to the lobby host ID, and was failing the call if not the same. But I also store the Service Account ID in the same field as the local player ID (on my server build), so the condition was not true ...

    And I totally overlooked the API to get a token on a Multiplay instance ! Right now, I pass the service account credential from the Configuration Variables, in the Build Configuration. The token has all the authorization to call any API ?
     
  4. mcanfield_unity

    mcanfield_unity

    Unity Technologies

    Joined:
    Mar 1, 2022
    Posts:
    13
    Ah, gotcha. Glad you figured it out!

    Unfortunately, no the token doesn't work on every single endpoint. I'll look to have this officially documented at some point, but for now below is a list of services that should work. If you have other ones that you were thinking of I can feed that back to the relevant folks. Good luck!
    • Cloud Code
    • Cloud Save
    • Economy
    • Leaderboards
    • Lobby
    • Multiplay
    • Relay
    • Friends
    • Realm (closed beta)
    • RoamingDB (closed beta)
     
    BSimonSweet likes this.