Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved How do I access service account keys to use AdminApiClient from cloudcode module

Discussion in 'Cloud Code' started by samhain323, May 14, 2024.

  1. samhain323

    samhain323

    Joined:
    Aug 4, 2020
    Posts:
    37
    Hello,

    I'm trying to write some leaderboard resets and such from my cloud code module using the AdminApiClient. However, the method parameters require service account keys and such. How can I access them from a cloudcode module?

    For instance, the method below asks for the serviceAccountKey and serviceAccountSecret. Is there a way to pass this in or access it from the context?

    GetLeaderboardVersionScoresPlayerRangeAsync(IExecutionContext executionContext, string serviceAccountKey, string serviceAccountSecret, Guid projectId, Guid environmentId, string leaderboardId, string versionId, string playerId, int? rangeLimit = null, CancellationToken cancellationToken = default(CancellationToken));
     
  2. MariusUrbelis

    MariusUrbelis

    Unity Technologies

    Joined:
    Mar 15, 2015
    Posts:
    47
    Hey! Here is a tutorial on how to create a service account and obtain these credentials: https://docs.unity.com/ugs/en-us/ma...ion-service-accounts#Create_a_service_account

    This is from Game Server Hosting. Therefore, one step will be different. Instead of adding a Multiplayer role in step 8, you will need to add a Leaderboards Admin project role. Then generate a key and those will be the required credentials.

    Let me know if you run into any issues!
     
    GabKBelmonte likes this.
  3. samhain323

    samhain323

    Joined:
    Aug 4, 2020
    Posts:
    37
    Thanks, but I have that. I have a service account and keys. What I don't know, is how I can obtain the key via api's as opposes to storing it in my code somewhere. I.e. is there anyway we can access environment variables from our cloudcode module?
     
  4. MariusUrbelis

    MariusUrbelis

    Unity Technologies

    Joined:
    Mar 15, 2015
    Posts:
    47
    Thanks for clarifying. Unfortunately as of right now you would have to store those keys hardcoded into your Cloud Code module code. We are working on a secrets manager that would securely store and let you access your service account credentials.
     
    GabKBelmonte likes this.
  5. samhain323

    samhain323

    Joined:
    Aug 4, 2020
    Posts:
    37
    great, thank you.

    Would you recommend hard coding them for now, or using a private game item to store and obtain them?
     
  6. MariusUrbelis

    MariusUrbelis

    Unity Technologies

    Joined:
    Mar 15, 2015
    Posts:
    47
    The easiest way would be to store it somewhere in the code if that module is the only one you are going to use for accessing the services. Otherwise you could explore putting that in Cloud Save.
     
    samhain323 likes this.
  7. samhain323

    samhain323

    Joined:
    Aug 4, 2020
    Posts:
    37
    thanks again