public async void TestForNotFoundWithImportantInfo(UUnitTestContext testContext) { var eReq = new AuthenticationModels.GetEntityTokenRequest(); eReq.Entity = new AuthenticationModels.EntityKey(); eReq.Entity.Type = "title"; eReq.Entity.Id = testTitleData.titleId; var multiApiSettings = new PlayFabApiSettings(); multiApiSettings.TitleId = testTitleData.titleId; multiApiSettings.DeveloperSecretKey = testTitleData.developerSecretKey; var authApi = new PlayFabAuthenticationInstanceAPI(multiApiSettings); var tokenTask = await authApi.GetEntityTokenAsync(eReq); testContext.IsNull(tokenTask.Error, "Failed to retrieve the Title Entity Token, check your playFabSettings.staticPlayer: " + PlayFabSettings.staticPlayer.EntityType); if (aliasId == "") { testContext.Fail("aliasId was blank, we will not get the expected failed NotFound response this test is asking for. Make sure testTitleData.json has a valid aliasId listed (check playfab multiplayer dashboard for your own valid aliasId)"); } MultiplayerModels.UpdateBuildAliasRequest updateBuildAliasRequest = new MultiplayerModels.UpdateBuildAliasRequest() { AliasId = aliasId, AliasName = "aliasName", AuthenticationContext = new PlayFab.PlayFabAuthenticationContext() { EntityToken = tokenTask.Result.EntityToken }, }; var multiplayerApi = new PlayFabMultiplayerInstanceAPI(multiApiSettings, updateBuildAliasRequest.AuthenticationContext); PlayFab.PlayFabResult <MultiplayerModels.BuildAliasDetailsResponse> res = await multiplayerApi.UpdateBuildAliasAsync(updateBuildAliasRequest); string response = PlayFab.PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(res); if (response.Contains("MultiplayerServerNotFound") && res.Error.HttpCode == 404) { testContext.EndTest(UUnitFinishState.PASSED, null); } else { testContext.Fail("We called the Mutliplayer API expecting to not find anything, but we didn't detect this to be the error. Details: " + res.Error.GenerateErrorReport() + " and http code: " + res.Error.HttpCode); } }
/// <summary> /// A coroutine to wait until we get an Entity Id after PlayFabLogin /// </summary> /// <param name="secondsBetweenWait">delay wait between checking whether Entity has logged in</param> private IEnumerator WaitUntilEntityLoggedIn(float secondsBetweenWait) { WaitForSeconds delay = new WaitForSeconds(secondsBetweenWait); while (true) { if (PlayFabAuthenticationAPI.IsEntityLoggedIn()) { if (entityKey.Id == null) { AuthenticationModels.GetEntityTokenRequest request = new AuthenticationModels.GetEntityTokenRequest(); PlayFabAuthenticationAPI.GetEntityToken(request, GetEntityTokenCompleted, GetEntityTokenFailed); } break; } yield return(delay); } }
/// <summary> /// Grabs the developer secret key from the environment variable (expected to be set) and uses it to /// ask the PlayFab server for a title entity token. /// </summary> /// <returns>The title's entity token</returns> private static async Task <string> GetTitleEntityToken() { var titleEntityTokenRequest = new AuthenticationModels.GetEntityTokenRequest(); var getEntityTokenUrl = GetServerApiUri("/Authentication/GetEntityToken"); // Grab the developer secret key from the environment variables (app settings) to use as header for GetEntityToken var secretKey = Environment.GetEnvironmentVariable(DEV_SECRET_KEY, EnvironmentVariableTarget.Process); if (string.IsNullOrEmpty(secretKey)) { // Environment variable was not set on the app throw new Exception("Could not fetch the developer secret key from the environment. Please set \"PLAYFAB_DEV_SECRET_KEY\" in your app's local.settings.json file."); } var titleEntityTokenRequestContent = new StringContent(PlayFabSimpleJson.SerializeObject(titleEntityTokenRequest)); titleEntityTokenRequestContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); titleEntityTokenRequestContent.Headers.Add("X-SecretKey", secretKey); using (var titleEntityTokenResponseMessage = await httpClient.PostAsync(getEntityTokenUrl, titleEntityTokenRequestContent)) { using (var titleEntityTokenResponseContent = titleEntityTokenResponseMessage.Content) { string titleEntityTokenResponseString = await titleEntityTokenResponseContent.ReadAsStringAsync(); // Deserialize the http response var titleEntityTokenResponseSuccess = PlayFabSimpleJson.DeserializeObject <PlayFabJsonSuccess <AuthenticationModels.GetEntityTokenResponse> >(titleEntityTokenResponseString); // Extract the actual get title entity token header var titleEntityTokenResponse = titleEntityTokenResponseSuccess.data; return(titleEntityTokenResponse.EntityToken); } } }
public void GetEntityToken(UUnitTestContext testContext) { var tokenRequest = new AuthenticationModels.GetEntityTokenRequest(); PlayFabAuthenticationAPI.GetEntityToken(tokenRequest, PlayFabUUnitUtils.ApiActionWrapper <AuthenticationModels.GetEntityTokenResponse>(testContext, GetTokenCallback), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext); }