Arnau Castillo avatar image
Arnau Castillo asked

Azure Function PLAYFAB_DEV_SECRET_KEY simple question


I am working on uploading leaderboard scores with Azure Functions in my Unity Game. For now I have succeeded (the Azure Function works perfectly), but I have one doubt.

This is the Azure Function:

namespace FuncionRankingPrueba1
    public static class RankingPrueba
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
            string name;
            string time;
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = data?.FunctionArgument?.name;
            time = data?.FunctionArgument?.time;
            int timeint = int.Parse(time);

            var request = new UpdatePlayerStatisticsRequest
                PlayFabId = data.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                Statistics = new List<StatisticUpdate>
                new StatisticUpdate
                    StatisticName = name,
                    Value = timeint
            var apiSettings = new PlayFabApiSettings
                TitleId = data.TitleAuthenticationContext.Id,
                DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process),
            var serverApi = new PlayFabServerInstanceAPI(apiSettings);
            return await serverApi.UpdatePlayerStatisticsAsync(request);

I have added an Application Settings in Azure that is the PLAYFAB_DEV_SECRET_KEY, with my SECRET KEY found in Title Settings, so when Environment.GetEnvironmentVariable is called, it founds my DEV_SECRET_KEY. Without this, it doesn't work.

My question is: when I publish my game on the Play Store, do the players use my PLAYFAB_DEV_SECRET_KEY to update their score or do I need to change something of my azure function code?

For example this line of code.

DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process)

Do I also need to change any setting on the Azure Portal?

I don't know if the set up that I have right now is good for testing everything but not when a lot of players upload their scores once the game is on the Play Store.


apisCloudScriptLeaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Made Wang avatar image
Made Wang answered

Your code doesn't need to be modified. Regarding PLAYFAB_DEV_SECRET_KEY, it is a global parameter you declare in the Azure portal, you can also declare any custom parameter in the Azure portal. And, because you are calling the serverAPI, you need to get the SECRET KEY, which is required both in AzureFunction and other servers. Are you worried about security? In fact, clients can only call this method, they can't know the content of the method, nor can they get the PLAYFAB_DEV_SECRET_KEY.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Arnau Castillo avatar image Arnau Castillo commented ·

Thanks a lot. You are always there to answer my questions. Sorry if I ask too many. I am completely alone making my game and I have to take care of everything (Leaderboards, Security, Game Design, Level Design, 3D modeling, all the UI and UX, etc...) and it is a little bit overwhelming.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.