question

peg avatar image
peg asked

Clean example of Azure Function Authentication using Playfab w/ Unity?

Background: I have been using Playfab for a while in Unity to do updates from the client side, this has been working fine. But I have some needs which require a server side security.

Test Case Goal

I am trying to set up a a dead simple test case before doing anything more complicated, here is what I am trying to do:

  • From Unity, call a Function set up in Playfab via PlayFabCloudScriptAPI.ExecuteFunction and make sure it gets the active Player ID

  • Have the function properly authenticate with the Azure Function so inside the Function I have access to the Player and API

  • Set a value for a statistic for that player

What I've Done So Far

  • Set up an Azure Function. It works. If I make an Anonymous Function I can successfully hook up in Playfab and call it from the Unity Client.

  • Make it work with Playfab with AuthorizationLevel.Function -- this is where it falls apart, have tried dozens of examples from these forums and docs, always some variety of authentication error. I have set up Application Settings w/ my Playfab Secret Key and Title Id, and could I guess use that to connect to Server API, but isn't the point of this system to have Playfab automatically authenticate? That's what the example seem to indicate?

My Question Is there a straightforward CURRENT example, here in December 2023, that shows exactly how to set up the Azure Function to properly authenticate, and how to call it from the game API (preferably Unity).

Sorry for the lengthy question, was trying to make it clear I've read past threads to see if I can get some better pointers on next steps. Appreciate any help!

apisAuthentication
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

·
Neils Shi avatar image
Neils Shi answered

Could you tell us what the authentication error you encountered so that we can do some research? For more information about how to set up an Azure Function, you can refer to PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Learn. And our documentation also provides sample code on how to call Azure Functions from Unity : Calling your function from Unity. In the HelloWorld example which you mentioned, SetObjects is a PlayFab API which is used to set objects on an entity's profile, the “foo” is a property of the object “obj1” that is being set on the entity’s profile, and the value of foo is set to "some server computed value", it doesn't have any special meaning. In addition, we recommend that you debug locally before deploying it to Azure, you can follow this documentation Local debugging for Cloudscript using Azure Functions - PlayFab | Microsoft Docs to do the locally debugging.

10 |1200

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

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.