question

claytoniousmojo avatar image
claytoniousmojo asked

Server API access to entities

I'm attempting to access a title_player_account entity from our server using the C# SDK.

var getEntityTokenRequest = new GetEntityTokenRequest
{
    Entity = new PlayFab.AuthenticationModels.EntityKey
    {
        Id = <ID_FROM_CLIENT>,
        Type = "title_player_account"
    }
};
var getTokenResponse = await PlayFabAuthenticationAPI.GetEntityTokenAsync(getEntityTokenRequest);

When I make this request, it returns with an error in the response object saying "The claim was not allowed to perform the requested action based on the entity's access policy. Policy comment: By default, all requests are denied. If you expected this request to succeed, you may be missing a policy. See the permissions APIs in PlayFab's Admin Api to add a permission."

I'm searching the documentation for something explaining what to do here but coming up empty. Any help would be greatly appreciated. Thanks!

entitiesAuthentication
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JayZuo avatar image
JayZuo answered

While in Server environment, you should only get "title" EntityToken, not "title_player_account" or any other Entity types. "title" token has full access of the entities in your title. You can use it to perform actions against "title_player_account". For example:

PlayFabSettings.TitleId = "your title Id";
PlayFabSettings.DeveloperSecretKey = "your secret key";

var getTitleEntityTokenRequest = new GetEntityTokenRequest(); //Do not need to set Entity
var titleEntityResponse = await PlayFabAuthenticationAPI.GetEntityTokenAsync(getTitleEntityTokenRequest);
if (titleEntityResponse.Result != null)
{
    Debug.WriteLine($"{titleEntityResponse.Result.Entity.Type} : {titleEntityResponse.Result.Entity.Id}");

    var data = new Dictionary<string, object>()
    {
        { "Health", 100 },
        { "Mana", 10000 }
    };

    var dataList = new List<SetObject>()
    {
        new SetObject()
        {
            ObjectName = "PlayerData",
            DataObject = data
        }
    };

    var response = await PlayFabDataAPI.SetObjectsAsync(new SetObjectsRequest()
    {
        Entity = new PlayFab.DataModels.EntityKey { Id = <ID_FROM_CLIENT>, Type = "title_player_account" },
        Objects = dataList,
    });

    Debug.WriteLine(response.Result?.ProfileVersion);
}

Entity calls are not made with the Server API (or the Client or Admin API). They are made with the Entity API.

The authentication on the call determines the entity that is making the call, and so the permissions. Please have a look at this updated thread for specifics on using the entity API calls from a custom game server: https://community.playfab.com/questions/19542/server-get-character-entity.html

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.