Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Arnau Castillo · Feb 26 at 02:45 PM · CloudScriptapisLeaderboards and Statistics

Azure Function PLAYFAB_DEV_SECRET_KEY simple question

Hi.


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
    {
        [FunctionName("UpdateRanking2602V3")]
        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.

Thanks.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Made Wang · Feb 28 at 07:36 AM

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.

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arnau Castillo · Feb 28 at 11:57 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    11 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    best practice for saving statistics for leaderboards 1 Answer

    Can Cloud Code Access the Admin API 1 Answer

    Update Statistic: invocation of cloud script function failed 1 Answer

    CustomTags conditions,Custom tag in conditions 2 Answers

    Advantages of CloudScript over Calling JavaScript from Node.js 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges