Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Multiplayer Hosting Game API (1.0) authorization does not work

Discussion in 'Game Server Hosting' started by airburst_studios, Apr 3, 2023.

  1. airburst_studios

    airburst_studios

    Joined:
    Jan 7, 2023
    Posts:
    35
    Hey there,
    I am trying to access the Multiplayer Hosting Game API (1.0) however I always receive a 401 not authorized response.

    I really tried everything. I created a service account and enabled all Multiplay related roles. I created the base64 authorization header and send it to the endpoint.

    To test if my authorization does indeed work I test it with the Multiplayer Hosting API (1.0) and fetched the fleet and test allocation info successfully. Indeed it does work for Multiplayer Hosting API (1.0) and not for Multiplayer Hosting Game API (1.0) requests.

    I also created a token via https://services.api.unity.com/auth/v1/token-exchange?projectId=7<projectid>&environmentId=<envId> but that did not made a difference - still 401


    Can you guys please check this out because I need to deallocate my servers if a match is finished - otherwise the whole server list blows up and I don't want to remove them manually.
     
  2. airburst_studios

    airburst_studios

    Joined:
    Jan 7, 2023
    Posts:
    35
    Ok I just figured out what's happening.

    For the Multiplayer Hosting Game API (1.0) you have to use the Token Exchange instead of the simple base64 token.


    1. Follow the steps for creating a token: https://services.docs.unity.com/docs/service-account-auth/index.html
    2. However I was using "Authorization Basic" instead of Bearer - you have to use Bearer in case you use the token otherwise it will give you a 401. It took me hours to figure that out.
     
    Last edited: Apr 3, 2023
    larah3d likes this.
  3. danri

    danri

    Unity Technologies

    Joined:
    Jun 21, 2019
    Posts:
    27
    Hello,

    Thanks for the original report and the follow up. The solution you propose here is covered by our documentation, near the bottom of the page you referenced - https://services.docs.unity.com/doc...ex.html#extra-step-use-the-token-exchange-api.

    It basically comes down to:

    We're aware that the structure of this page could be improved for clarity and we will be working on this moving forward.
     
  4. airburst_studios

    airburst_studios

    Joined:
    Jan 7, 2023
    Posts:
    35
    Yeah it's mostly me skipping the relevant parts. Happens all the time. However maybe a "Important" notification might help future me's to not fall into that