Hello, I've a simple azure function to get a sharedgroup from playfab server api:
[FunctionName("GetSharedGroup")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req) { var context = await FunctionContext<GetSharedGroupRequest>.Create(req); var request = new GetSharedGroupDataRequest { AuthenticationContext = context.AuthenticationContext, SharedGroupId = context.FunctionArgument.SharedGroupId }; var playfabServerInstanceAPI = new PlayFabServerInstanceAPI( new PlayFabApiSettings { TitleId = Environment.GetEnvironmentVariable(Constants.PLAYFAB_TITLE_ID, EnvironmentVariableTarget.Process), VerticalName = Environment.GetEnvironmentVariable(Constants.PLAYFAB_CLOUD_NAME, EnvironmentVariableTarget.Process), DeveloperSecretKey = Environment.GetEnvironmentVariable(Constants.PLAYFAB_DEV_SECRET_KEY, EnvironmentVariableTarget.Process) } ); return await playfabServerInstanceAPI.GetSharedGroupDataAsync(request); }
FunctionContext<TFunctionArgument> is referenced from PlayFab.Plugins.CloudScript but it does not work and throws object reference not set to an instance of an object exception. I guess PlayFab.Plugins.CloudScript is outdated.
If I replace my code with this :
[FunctionName("GetSharedGroup")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req) { var context = JsonConvert.DeserializeObject<FunctionExecutionContext<JoinMatchRequest>>(await req.Content.ReadAsStringAsync()); var request = new GetSharedGroupDataRequest { AuthenticationContext = new PlayFabAuthenticationContext { EntityToken = context.TitleAuthenticationContext.EntityToken }, SharedGroupId = context.FunctionArgument.SharedGroupId }; var playfabServerInstanceAPI = new PlayFabServerInstanceAPI( new PlayFabApiSettings { TitleId = Environment.GetEnvironmentVariable(Constants.PLAYFAB_TITLE_ID, EnvironmentVariableTarget.Process), VerticalName = Environment.GetEnvironmentVariable(Constants.PLAYFAB_CLOUD_NAME, EnvironmentVariableTarget.Process), DeveloperSecretKey = Environment.GetEnvironmentVariable(Constants.PLAYFAB_DEV_SECRET_KEY, EnvironmentVariableTarget.Process) } ); return await playfabServerInstanceAPI.GetSharedGroupDataAsync(request); }
It works, but the problem here is that as you see I am manually creating PlayFabAuthenticationContext and I pass only EntityToken, but I can not pass ClientSessionTicket because sample models don't have it. I was following this documentation and I've manually imported sample models into my project:.
https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart#playfab-cloudscript-context-variables-and-server-sdks-
Is it a best practice to use cloud script and azure functions like this or am I missing something. Also it's strange that PlayFab.Plugins.CloudScript does not work, because the official example also uses it: