question

Chris Ross avatar image
Chris Ross asked

Connecting the dots between Legacy CloudScript and Azure Cloud Functions

I am slowly losing my mind at the moment:

We have a development title that had a bunch of CloudScript JS code. With that being made legacy, we have chosen to migrate code to Azure Cloud Functions.

Using PlayFab.Plugins.CloudScript and the FunctionContext to unpack the values coming in from PlayFab.

So far so good.

However, the problem arises in that API calls require the PlayFab user ID, but the .CurrentPlayerId that is attached to the function context is the entity id for the player's account.

I can find no way to get a valid PlayFab user ID for a given entity, which means I am able to call the cloud function, but I'm unable to actually use any of the PlayFab REST API calls through PlayFabServerInstanceAPI to do anything.

What am I missing here?

- There is a recent post that suggests that PlayFab.Plugins.CloudScript is obsolete and that I should be using https://github.com/PlayFab/PlayFab-Samples/blob/master/Samples/CSharp/AzureFunctions/CS2AFHelperClasses.cs

- Yet, when you look at the examples - ExampleFunctions and TicTacToe - they are using PlayFab.Plugins.CloudScript, so what am I supposed to be doing?

- Looking at TicTacToe, the client passes up the PlayFab ID to the server to then apply things to an account, this seems insecure to me, is this how we should be doing things? How can we validate that the PlayFab Id provided by the client matches the same account the entity links to?

apisCloudScript
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

PlayFab.Plugins.CloudScript is obsolete, you need to use CS2AFHelperClasses.cs instead.

Add CS2AFHelperClasses.cs to your Azure Function project folder, reference the namespace PlayFab.Samples, then you can refer to the code below to get the PlayFabId of the client.

FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
string PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId;
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.