wup avatar image
wup asked

Creating CloudScript Azure Function - a few questions

I'm working with some friends to create a Unity game. I agreed to help them out with some back end pieces, particularly some API work. I'm not a game dev or super familiar with Unity,.

Somehow I'm having a hard time finding documentation is something that I would have been expected to be easy to find. So I apologize in advice for my stupid questions.

What I'm looking to do:

I have a bunch of existing Firebase Cloud Functions written in nodejs, and I'd like to port them to Playfab for use in the Unity game. I know C#, but some of the functionality is very specific to some NPM modules, so I have a very strong preference to keep the functions as nodejs.

Does it matter what language is used a Function if it's registered in CloudScript? I wouldn't have thought it would be important, but one of the Microsoft articles mentions that .NET core should be used. Maybe I'm reading too far into that statement though.

I'd like my functions to return information specific to a Playfab user. How does my authentication look? The article I was reading mentions just using "Function" authentication, but this sound like a full-trust authorization model between Playfab and the Function. Is it assumed Playfab itself will take care of the authorization, and passes in some sort of a PlayfabId for me to identify the user?

I would have hoped to receive some sort of oAuth2 Bearer token or something, but I haven't found anything that points to this being the case.

Also if anyone has any good resources for nodejs based Playfab Azure Function, I'd love to give it a read.


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

Azure Function Cloud Script supports Node.js, refer to Supported languages in Azure Functions | Microsoft Docs for all supported language versions, but there is currently no official sample.

When ExecuteFunction is called, the data is passed in the context model, which contains information about authentication, which can be found in PlayFab CloudScript using Azure Functions Context Models - PlayFab | Microsoft Docs.

10 |1200

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

wup avatar image wup commented ·

Thanks. Too bad about the lack of sample code in other languages. I like C# as much as the next guy, but node is pretty popular these days.

I found some useful properties at


And ended up using those to extract the Playfab Id of the player.

Another question for you, is there a best practice for checking the validity of the call? e.g., there seems to be an EntityToken that comes across. I tried validating it through PlayFabAuthentication.ValidateEntityToken() but it complains that it was an unexpected token (don't remember the exact error off-hand, it's been a few days).

Or can we just assume that because only PlayFab should have access to execute this function, that the context details can be trusted?

0 Likes 0 ·
Made Wang avatar image Made Wang wup commented ·

Normally, you do not need to manually authenticate when using AzureFunctionCloudScript. When the client calls the function, PlayFab will authenticate the client first, and then send the client information to Azure Function in the context model.

As for the authentication between Azure Function and PlayFab and the difference between different authentication levels, please check the related documents of Azure Function.

Also, if you want to get some identity information, you can refer to the code below. CS2AFHelperClasses.cs is used here, refer to this sample to learn more.

FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
var TitleEntityToken= context.TitleAuthenticationContext.EntityToken;
var TitleId = context.TitleAuthenticationContext.Id;
var PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId;
var PlayerId= context.CallerEntityProfile.Lineage.TitlePlayerAccountId;
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.