public void StaticLogin(UUnitTestContext testContext)
        {
            var loginRequest = new LoginWithCustomIDRequest
            {
                CustomId      = PlayFabSettings.BuildIdentifier,
                CreateAccount = true,
            };
            var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(loginRequest);

            loginTask.Wait();

            testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "p2 client context leaked to static context");
            testContext.True(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "p2 entity context leaked to static context");

            testContext.False(client1.IsClientLoggedIn(), "Static login leaked to Client1");
            testContext.False(client2.IsClientLoggedIn(), "tatic login leaked to Client2");
            testContext.False(auth1.IsEntityLoggedIn(), "Static login leaked to Auth1");
            testContext.False(auth2.IsEntityLoggedIn(), "Static login leaked to Auth2");

            // Verify useful player information
            testContext.NotNull(PlayFabSettings.staticPlayer.PlayFabId);
            testContext.NotNull(PlayFabSettings.staticPlayer.EntityId);
            testContext.NotNull(PlayFabSettings.staticPlayer.EntityType);

            PlayFabClientAPI.ForgetAllCredentials();

            testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + loginTask.Result.Result.PlayFabId);
        }
Esempio n. 2
0
    public void CreateGroup(string adminUsername, string password, string groupName)
    {
        var loginWithPlayFabRequest = new LoginWithPlayFabRequest {
            Username = adminUsername, Password = password
        };

        PlayFabClientAPI.LoginWithPlayFab(loginWithPlayFabRequest,
                                          delegate(LoginResult loginResult)
        {
            PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest(),
                                                    delegate(GetEntityTokenResponse getEntityTokenResponse)
            {
                var createGroupRequest = new CreateGroupRequest {
                    GroupName = groupName,
                    Entity    = ConvertEntityKey(getEntityTokenResponse.Entity)
                };

                PlayFabGroupsAPI.CreateGroup(createGroupRequest,
                                             delegate(CreateGroupResponse response)
                {
                    Debug.Log("Group was successfully created: " + response.GroupName + " -  " + response.Group.Id);
                },
                                             SharedError.OnSharedError);
            },
                                                    SharedError.OnSharedError);
        },
                                          SharedError.OnSharedError);
    }
        public void GetPFTitleEntityToken()
        {
            if (_tokenRefreshTime < DateTime.UtcNow)
            {
                GetEntityTokenRequest request = new GetEntityTokenRequest();

                // Using reflection here since the property has an internal setter. Clearing it is essential, to force,
                // the SDK to use the secret key (and not send a potentially expired token). If the SDK behavior changes to use the secret key (if available),
                // then all this code can be removed
                FieldInfo fieldInfo = typeof(PlayFabSettings).GetField("staticPlayer", BindingFlags.Static | BindingFlags.NonPublic);

                PlayFabAuthenticationContext context = (PlayFabAuthenticationContext)fieldInfo.GetValue(null);

                fieldInfo = typeof(PlayFabAuthenticationContext).GetField("EntityToken", BindingFlags.Instance | BindingFlags.Public);
                fieldInfo.SetValue(context, null);

                PlayFabSettings.staticSettings.TitleId            = TitleId;
                PlayFabSettings.staticSettings.DeveloperSecretKey = _secretKey;

                // The SDK sets the entity token as part of response evaluation.
                PlayFabResult <GetEntityTokenResponse> response = PlayFabAuthenticationAPI.GetEntityTokenAsync(request).Result;
                if (response.Error != null)
                {
                    throw new Exception($"Error occurred while calling the api. {JsonConvert.SerializeObject(response.Error)}.");
                }

                _tokenRefreshTime = DateTime.UtcNow.AddHours(TokenRefreshIntervalInHours);
            }
        }
        public void Instance2Login(UUnitTestContext testContext)
        {
            var loginRequest = new LoginWithCustomIDRequest
            {
                CustomId      = PlayFabSettings.BuildIdentifier,
                CreateAccount = true,
            };
            var loginTask = client2.LoginWithCustomIDAsync(loginRequest);

            loginTask.Wait();

            testContext.True(player2.IsClientLoggedIn(), "player2 client login failed, ");
            testContext.True(client2.IsClientLoggedIn(), "client2 client login failed");
            testContext.True(player2.IsEntityLoggedIn(), "player2 entity login failed");
            testContext.True(auth2.IsEntityLoggedIn(), "auth2 entity login failed");

            testContext.False(PlayFabClientAPI.IsClientLoggedIn(), "p2 client context leaked to static context");
            testContext.False(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "p2 entity context leaked to static context");

            // Verify useful player information
            testContext.NotNull(player2.PlayFabId);
            testContext.NotNull(player2.EntityId);
            testContext.NotNull(player2.EntityType);

            testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + loginTask.Result.Result.PlayFabId);
        }
    public void WriteOneDSEvents(UUnitTestContext testContext)
    {
        // get Entity Token which is needed for work events
        PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest
        {
            CustomId = PlayFabSettings.BuildIdentifier,
            TitleId  = PlayFabSettings.TitleId
        }, loginCallback =>
        {
            PlayFabAuthenticationAPI.GetEntityToken(new GetEntityTokenRequest
            {
                AuthenticationContext = loginCallback.AuthenticationContext
            }, entityCallback =>
            {
#if TPL_35
                Task.Run(() => WriteOneDSEventsAsync(testContext));
#else
                WriteOneDSEventsAsync(testContext);
#endif
            }, entityError =>
            {
                testContext.Skip("EntityToken required!");
            });
        }, loginError =>
        {
            testContext.Skip("Login required!");
        });
    }
        static public async Task InitializeSettingsAndConnect()
        {
            PlayFabSettings.staticSettings.TitleId            = System.Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID");
            PlayFabSettings.staticSettings.DeveloperSecretKey = System.Environment.GetEnvironmentVariable("PLAYFAB_TITLE_SECRET_KEY");
            var result = await PlayFabAuthenticationAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest());

            entityToken = result.Result.EntityToken;
        }
 private void VerifyCleanCreds(UUnitTestContext testContext)
 {
     testContext.False(client1.IsClientLoggedIn(), "Client1 login did not clean up properly.");
     testContext.False(client2.IsClientLoggedIn(), "Client2 login did not clean up properly.");
     testContext.False(auth1.IsEntityLoggedIn(), "Entity1 login did not clean up properly.");
     testContext.False(auth2.IsEntityLoggedIn(), "Entity2 login did not clean up properly.");
     testContext.False(PlayFabClientAPI.IsClientLoggedIn(), "Static client login did not clean up properly.");
     testContext.False(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "Static entity login did not clean up properly.");
 }
Esempio n. 8
0
 void SetEntityToken()
 {
     PlayFabAuthenticationAPI.GetEntityToken
         (new GetEntityTokenRequest(),
         (result) => _entityKey = new EntityKey()
     {
         Id = result.Entity.Id, Type = result.Entity.Type
     },
         (err) => print(err.GenerateErrorReport()));
 }
        public static void GetEntityToken()
        {
            GetEntityTokenRequest request = new GetEntityTokenRequest();

            PlayFabAuthenticationAPI.GetEntityToken(request, GetEntityTokenResponseSuccess, Error, null, null);

            while (!loggedin)
            {
                Debug.Log("Not logged in");
            }
        }
        //[Button("Function")]
        #region PlayFab Multiplayer Server
        private void ListBuildSummaries()
        {
            if (!PlayFabAuthenticationAPI.IsEntityLoggedIn())
            {
                PlayFabGeneral.GetEntityToken();
            }

            ListBuildSummariesRequest request = new ListBuildSummariesRequest();

            PlayFabMultiplayerAPI.ListBuildSummaries(request, ListBuildSummariesResponseSuccess, PlayFabGeneral.Error, null, null);
        }
Esempio n. 11
0
        private void StaticLoginCallback(LoginResult result)
        {
            var testContext = (UUnitTestContext)result.CustomData;

            testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "static client login failed");
            testContext.True(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "static entity login failed");

            PlayFabClientAPI.ForgetAllCredentials();

            testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + result.PlayFabId);
        }
Esempio n. 12
0
        public static async Task <string> GetTitleEntityToken()
        {
            PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_SECRET_KEY", EnvironmentVariableTarget.Process);
            PlayFabSettings.staticSettings.TitleId            = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID", EnvironmentVariableTarget.Process);
            //PlayFabSettings.VerticalName = VERTICAL_NAME; //Environment.GetEnvironmentVariable(VERTICAL_NAME, EnvironmentVariableTarget.Process);

            var request = new GetEntityTokenRequest();
            PlayFabResult <GetEntityTokenResponse> response = await PlayFabAuthenticationAPI.GetEntityTokenAsync(request);

            return(response.Result?.EntityToken);
        }
Esempio n. 13
0
        private void GetPlayFabServers()
        {
            var getTitleEntityTokenRequest     = new GetEntityTokenRequest();
            GetEntityTokenRequest tokenRequest = new GetEntityTokenRequest();

            PlayFabAuthenticationAPI.GetEntityToken(tokenRequest, TokenResponseSuccess, Error, null, null);

            ListMultiplayerServersRequest request = new ListMultiplayerServersRequest();

            //request.BuildId = MMOClientInstance.Singleton.PlayFabManager.BuildIdKey;
            //request.Region = MMOClientInstance.Singleton.PlayFabManager.playFabRegion.ToString();

            PlayFabMultiplayerAPI.ListMultiplayerServers(request, GetServerList, Error, null, null);
        }
Esempio n. 14
0
        //Save character data
        public void TrySaveCharacterData(PlayFabCharacterData characterData)
        {
            GetEntityTokenRequest requestToken = GetTokenForRequest();

            PlayFabAuthenticationAPI.GetEntityToken(requestToken,
                                                    result =>
            {
                SaveCharacterData(characterData);
            },
                                                    error =>
            {
                Debug.Log($"Failed to get entity token");
            });
        }
Esempio n. 15
0
        public void ShutDownMultiplayerServer(string sessionId, string region)
        {
            if (!PlayFabAuthenticationAPI.IsEntityLoggedIn())
            {
                PlayFabServerInstance.singleton.GetEntityToken();
            }

            ShutdownMultiplayerServerRequest request = new ShutdownMultiplayerServerRequest();

            request.BuildId   = PlayFabServerInstance.singleton.BuildIdKey;
            request.SessionId = sessionId;
            request.Region    = region;
            PlayFabMultiplayerAPI.ShutdownMultiplayerServer(request, ShutdownMultiplayerServerSuccess, Error, null, null);
            Debug.Log("[PlayFabMultiplayerServer] Shutting Down: " + sessionId + " Region: " + region);
        }
Esempio n. 16
0
        void TryRetrieveCharacterData(ushort clientIdOfCaller, string characterID)
        {
            GetEntityTokenRequest requestToken = GetTokenForRequest();

            PlayFabAuthenticationAPI.GetEntityToken(requestToken,
                                                    result =>
            {
                Debug.Log("GetEntityToken call for GetCharacterData worked");
                RetrieveCharacterData(clientIdOfCaller, characterID);
            },
                                                    error =>
            {
                Debug.Log($"Failed to get entity token");
            });
        }
        private void StaticCallback(LoginResult result)
        {
            var testContext = (UUnitTestContext)result.CustomData;

            testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "p2 client context leaked to static context");
            testContext.True(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "p2 entity context leaked to static context");

            testContext.False(client1.IsClientLoggedIn(), "Static login leaked to Client1");
            testContext.False(client2.IsClientLoggedIn(), "tatic login leaked to Client2");
            testContext.False(auth1.IsEntityLoggedIn(), "Static login leaked to Auth1");
            testContext.False(auth2.IsEntityLoggedIn(), "Static login leaked to Auth2");

            PlayFabClientAPI.ForgetAllCredentials();

            testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + result.PlayFabId);
        }
Esempio n. 18
0
        public void ShutDownAllMultiplayerServer()
        {
            if (!PlayFabAuthenticationAPI.IsEntityLoggedIn())
            {
                PlayFabServerInstance.singleton.GetEntityToken();
            }

            foreach (KeyValuePair <string, string> server in servers)
            {
                ShutdownMultiplayerServerRequest request = new ShutdownMultiplayerServerRequest();
                request.BuildId   = PlayFabServerInstance.singleton.BuildIdKey;
                request.SessionId = server.Value;
                request.Region    = server.Key;
                PlayFabMultiplayerAPI.ShutdownMultiplayerServer(request, ShutdownMultiplayerServerSuccess, Error, null, null);
                Debug.Log("[PlayFabMultiplayerServer] Shutting Down: " + server.Value);
            }
        }
Esempio n. 19
0
        // retrieves and stores an auth token
        // returns false if it fails
        private static bool GetAuthToken()
        {
            var entityTokenRequest = new GetEntityTokenRequest();
            var authTask           = PlayFabAuthenticationAPI.GetEntityTokenAsync(entityTokenRequest);

            authTask.Wait();
            if (authTask.Result.Error != null)
            {
                OutputPlayFabError("\t\tError retrieving auth token: ", authTask.Result.Error);
                return(false);
            }
            else
            {
                authToken = authTask.Result.Result.EntityToken;
                LogToFile("\t\tAuth token retrieved.", ConsoleColor.Green);
            }
            return(true);
        }
        /// <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);
            }
        }
Esempio n. 21
0
    public void Authenticate()
    {
        ShowLoader();
        var request = new GetEntityTokenRequest();

        PlayFabAuthenticationAPI.GetEntityToken(request,
                                                result => {
            Debug.Log("GOT TOKEN OK: " + result.ToJson().ToString());
            Inform("Authentication Success!\n\nExpires " + result.TokenExpiration.Value.ToLocalTime().ToString());
            HideLoader();
            loginWindow.SetActive(false);
        }, error => {
            HideLoader();
            loginWindow.SetActive(true);
            Inform("GET TOKEN FAILED: " + error.ErrorMessage);
            Debug.LogError("GET TOKEN FAILED: " + error.ToString());
        });
    }
        private void Instance1Callback(LoginResult result)
        {
            var testContext = (UUnitTestContext)result.CustomData;

            testContext.True(player1.IsClientLoggedIn(), "player1 client login failed, ");
            testContext.True(client1.IsClientLoggedIn(), "client1 client login failed");
            testContext.True(player1.IsEntityLoggedIn(), "player1 entity login failed");
            testContext.True(auth1.IsEntityLoggedIn(), "auth1 entity login failed");

            testContext.False(PlayFabClientAPI.IsClientLoggedIn(), "p1 client context leaked to static context");
            testContext.False(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "p1 entity context leaked to static context");

            // Verify useful player information
            testContext.NotNull(player1.PlayFabId);
            testContext.NotNull(player1.EntityId);
            testContext.NotNull(player1.EntityType);

            testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + result.PlayFabId);
        }
Esempio n. 23
0
        private static async Task GetTitleData(string titleId, string secretKey)
        {
            try
            {
                PlayFabSettings.TitleId            = titleId;
                PlayFabSettings.DeveloperSecretKey = secretKey;

                var tokenRequest = new GetEntityTokenRequest()
                {
                    Entity = new EntityKey()
                    {
                        Type = "Title"
                    }
                };
                PlayFabResult <GetEntityTokenResponse> tokenResponse =
                    await PlayFabAuthenticationAPI.GetEntityTokenAsync(tokenRequest);

                if (tokenResponse.Error != null)
                {
                    LogMessage($"Error retrieving entity token: {tokenResponse.Error.Error.ToString()}: {tokenResponse.Error.ErrorMessage}");
                }

                PlayFabResult <GetTitleDataResult> titleData =
                    await PlayFabServerAPI.GetTitleDataAsync(new GetTitleDataRequest());

                if (titleData.Error != null)
                {
                    LogMessage($"Error retrieving title data: {titleData.Error.Error.ToString()}: {titleData.Error.ErrorMessage}");
                }
                else
                {
                    LogMessage("Title Data:");
                    foreach (KeyValuePair <string, string> titleDataTuple in titleData.Result.Data)
                    {
                        LogMessage($"\t{titleDataTuple.Key}={titleDataTuple.Value}");
                    }
                }
            }
            catch (Exception e)
            {
                LogMessage($"Exception calling for titleData {e}");
            }
        }
Esempio n. 24
0
    public void UploadUD2()
    {
        if (PlayFabAuthenticationAPI.IsEntityLoggedIn())
        {
            //Debug.Log("PlayFab - UpdateData");

            Dictionary <string, string> data = new Dictionary <string, string>();
            data = CharacterReferences.instance.playerInfo.GetData2();

            var request = new UpdateUserDataRequest {
                Data = data
            };
            PlayFabClientAPI.UpdateUserData(request, OnUpdateUserDataSuccess2, OnUpdateUserDataFailure);
        }
        else
        {
            LogInWindow.SetActive(true);
        }
    }
Esempio n. 25
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            // Update the PlayFabSettings with dev secret key and title ID
            if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.DeveloperSecretKey))
            {
                PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PlayFab.TitleSecret", EnvironmentVariableTarget.Process);
            }

            if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
            {
                PlayFabSettings.staticSettings.TitleId = Environment.GetEnvironmentVariable("PlayFab.TitleId", EnvironmentVariableTarget.Process);
            }

            var titleResponse = await PlayFabAuthenticationAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest());

            var title      = titleResponse.Result.Entity;
            var titleToken = titleResponse.Result.EntityToken;

            log.LogInformation($"Title is  : {title.Id}");
            log.LogInformation($"Token is  : {titleToken}");

            var request = new PlayFab.GroupsModels.ListMembershipRequest()
            {
                Entity = new PlayFab.GroupsModels.EntityKey
                {
                    Id   = "7B66887BFE1A76CE",
                    Type = "title_player_account",
                }
            };

            log.LogInformation($"Request is  : {JsonConvert.SerializeObject(request)}");

            var result = await PlayFabGroupsAPI.ListMembershipAsync(request);

            var groups = result.Result.Groups;
            var msg    = $"group is {JsonConvert.SerializeObject(groups)}\n";

            return((ActionResult) new OkObjectResult($"{msg}"));
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
 public override void ClassTearDown()
 {
     PlayFabAuthenticationAPI.ForgetAllCredentials();
 }
Esempio n. 28
0
 public virtual void Logout()
 {
     PlayFabAuthenticationAPI.ForgetAllCredentials();
 }
Esempio n. 29
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Welcome to the MpsAllocatorSample! This sample allows you to easily call frequently used APIs on your MPS Build");
            string titleId = Environment.GetEnvironmentVariable("PF_TITLEID");

            if (string.IsNullOrEmpty(titleId))
            {
                Console.WriteLine("Enter TitleID");
                titleId = Console.ReadLine();
            }

            PlayFabSettings.staticSettings.TitleId = titleId;

            string secret = Environment.GetEnvironmentVariable("PF_SECRET");

            if (string.IsNullOrEmpty(secret))
            {
                Console.WriteLine("Enter developer secret key");
                secret = Console.ReadLine();
            }

            PlayFabSettings.staticSettings.DeveloperSecretKey = secret;

            var req = new PlayFab.AuthenticationModels.GetEntityTokenRequest();

            var res = await PlayFabAuthenticationAPI.GetEntityTokenAsync(req);

            bool exitRequested = false;

            while (!exitRequested)
            {
                int option = PrintOptions();

                switch (option)
                {
                case 0:
                    exitRequested = true;
                    break;

                case 1:
                    await RequestMultiplayerServer();

                    break;

                case 2:
                    await ListBuildSummaries();

                    break;

                case 3:
                    await GetBuild();

                    break;

                case 4:
                    await ListMultiplayerServers();

                    break;

                case 5:
                    await ListVirtualMachineSummaries();

                    break;

                case 6:
                    await GetMultiplayerServerDetails();

                    break;

                case 7:
                    await PrintServerStateInVM();

                    break;

                default:
                    Console.WriteLine("Please enter a valid option");
                    continue;
                }
            }
        }
        public void GetEntityToken()
        {
            GetEntityTokenRequest request = new GetEntityTokenRequest();

            PlayFabAuthenticationAPI.GetEntityToken(request, GetEntityTokenResponseSuccess, Error, null, null);
        }