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);
            }
        }
예제 #2
0
        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;
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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}");
            }
        }
예제 #6
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}"));
        }
예제 #7
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;
                }
            }
        }
예제 #8
0
        public void GetEntityToken(UUnitTestContext testContext)
        {
            var writeTask = PlayFabAuthenticationAPI.GetEntityTokenAsync(new GetEntityTokenRequest(), null, extraHeaders);

            ContinueWithContext(writeTask, testContext, GetEntityTokenContinued, true, "GetEntityToken failed", true);
        }