Hello,
Upon players registering to our service through AddUsernamePassword, we need the ability to set their contact email (only available from the client API) and to remove tags. We're trying to put these critical steps on the server rather than on our unity client, as we want to remove risks of connection issues between the client / server in between these steps. AddUsernamePassword doesn't seem to generate any PlayStream event, so we can't hook a cloudscript on that event which would then trigger some logic server side.
I've been setting up Azure Functions to do all the steps mentioned above, as a moderator mentioned that it has access to the client API. The unity client calls this azure function, which makes calls to the client API (AddUsernamePasswordAsync, then AddOrUpdateContactEmailAsync). I can also use rules to trigger some further actions when that Azure Function is called.
Everything seems to be working, but I just stumbled upon this thread, in which it is suggested that we should never use the client API from Azure Functions, since we would hit the rate limit. So...
Question A: are we supposed to use the Client API at all in Azure Functions, or is it not a recommended practice?
If there exists a proper way to use the client API from Azure Functions, I'd like to confirm we're using it properly.
This sample code readme says there are "authentication objects that you can use to create PlayFab instance API clients in an Azure Function". In my case I seem forced to always create a new client instance from the Azure Function, and login with it in order to call other API methods:
var playerSettings = new PlayFab.PlayFabApiSettings() { TitleId = titleID, }; var clientInstanceAPI = new PlayFabClientInstanceAPI(playerSettings); /// LOGIN CLIENT var clientLoginRequest = new LoginWithCustomIDRequest { CreateAccount = false, TitleId = titleID, CustomId = customID };
I've tried creating the client instance API with context.AuthenticationContext instead.
var context = await FunctionContext<RegisterAccountRequest>.Create(req); var clientInstanceAPI = new PlayFabClientInstanceAPI(context.AuthenticationContext);
When trying to call client API methods with that instance, I get an error message saying the client "Must be logged in to call this method". Upon further investigation, context.AuthenticationContext.ClientSessionTicket is null and context.AuthenticationContext.IsClientLoggedIn() is false. From the unity client, I've tried passing different arguments in ExecuteFunctionRequest.Entity.ID and .Type that I received when the unity client logged in, but that didn't seem to change the context.AuthenticationContext in the Azure Function.
Question B: are we supposed to reuse the unity client authentication context to initialize the client API in azure functions, and if we are, could you provide code samples on how to do this?
Finally, this section mentions we should not use static API for very good reasons, but I'm not 100% certain what this means in the context of azure functions.
Question C: Could you clarify if the first code sample above uses a static API?
Thanks a lot for your help.