question

Noki yer avatar image
Noki yer asked

Is GetEntityToken required after LoginWithCustomID?

I am just starting to play around with PlayFab! I am using the new Entity model for the apis and using the lua sdk..

I could successfully login using LoginWithCustomID. I then want to store some player data in an object. I tried this via a call to SetObjects and passed the Entity Key (saved from the login request) . However, i get a message that this is an unauthenticated call and i need to use GetEntityToken. Is the Entity Token and expiration received from the login response not saved?

apis
10 |1200

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

Noki yer avatar image
Noki yer answered

Thanks a lot.. That was quite useful and i could see that the response from the login call has the EntityToken

I think what is happening is that the EntityToken in the settings file is not set after the login call.

Below is the function from https://github.com/PlayFab/LuaSdk/blob/master/PlayFabClientSDK/PlayFab/PlayFabClientApi.lua

function PlayFabClientApi.LoginWithCustomID(request, onSuccess, onError) request.TitleId = PlayFabSettings.settings.titleId local externalOnSuccess = onSuccess function wrappedOnSuccess(result) PlayFabSettings._internalSettings.sessionTicket = result.SessionTicket if (result.Entity) then PlayFabSettings._internalSettings.entityToken = result.Entity.EntityToken end if (externalOnSuccess) then externalOnSuccess(result) end PlayFabClientApi._MultiStepClientLogin(result.SettingsForUser.NeedsAttribution) end onSuccess = wrappedOnSuccess IPlayFabHttps.MakePlayFabApiCall("/Client/LoginWithCustomID", request, nil, nil, onSuccess, onError) end

I changed line 873 in that file to:

if (result.EntityToken) then PlayFabSettings._internalSettings.entityToken = result.EntityToken.EntityToken end

After this change, the call the Set/Get Objects works.. So would it be possible to check with whoever maintains the Lua SDK please whether what i did is correct and needed..

8 comments
10 |1200

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

Seth Du avatar image Seth Du ♦ commented ·

Thanks for the feedback. I will report this issue to the team.

0 Likes 0 ·
franklinchen avatar image franklinchen Seth Du ♦ commented ·

Thank you for reporting this Entity token setting related issue in Lua sdk, the engineering team has pushed a fix, we should see it in the recent update. Thanks

0 Likes 0 ·
Noki yer avatar image Noki yer franklinchen commented ·

Thanks for the fix and i can see that the Lua sdk has been updated recently. However, the fix does not work as it has only partially changed the statement.

Instead of the change below that you have made..

if (result.Entity) then PlayFabSettings._internalSettings.entityToken = result.EntityToken.EntityToken end

.. it should be

if (result.EntityToken) then PlayFabSettings._internalSettings.entityToken = result.EntityToken.EntityToken end

0 Likes 0 ·
Show more comments
Noki yer avatar image Noki yer commented ·

Please advise when this is likely to be fixed as i my project keeps refreshing from github and i need to then keep fixing it manually.

0 Likes 0 ·
franklinchen avatar image franklinchen Noki yer commented ·

Hi @Noki yer, I just try to ask the status of this fix, we don't have ETA right now, but I will keep tracking it and notify you here, thanks for your understanding.

0 Likes 0 ·
franklinchen avatar image franklinchen Noki yer commented ·

The fix has been published to the latest Lua SDK. Thanks.

0 Likes 0 ·
Seth Du avatar image
Seth Du answered

>>Is GetEntityToken required after LoginWithCustomID?

No. Entity token will also be returned in the successful callback of login API. If you are new to PlayFab, we highly recommend you to use Restful API testing tools like Postman to learn PlayFab, where you may see the full callback clearly. Here is an example:

{
    "code": 200,
    "status": "OK",
    "data": {
        "SessionTicket": "xxxxxx",
        "PlayFabId": "xxxxxx",
        "NewlyCreated": false,
        "SettingsForUser": {
            "NeedsAttribution": false,
            "GatherDeviceInfo": true,
            "GatherFocusInfo": true
        },
        "LastLoginTime": "2020-01-03T02:39:44.85Z",
        "EntityToken": {
            "EntityToken": "xxxxxxxxxxx",
            "TokenExpiration": "2020-01-07T09:12:25.434Z",
            "Entity": {
                "Id": "xxxxxxx",
                "Type": "title_player_account",
                "TypeString": "title_player_account"
            }
        }
    }
}

Entity token, like Session ticket, is an access token for PlayFab service. Session Ticket is the access token for the legacy API calls(client API, server API, etc.), meanwhile Entity token is the one for entity related APIs, like Group, Objects, Multiplayer 2.0.

The Entity token should share the same expiration time with session ticket. As long as you have logged in, the returned Session ticket, with the entity token, will last around 24 hours.

I am not familiar with Lua, and it will take some time for me to implement the sdk, but can you find and output the entity token configured in a place like "PlayFabAuthenticationContext" in C# SDK, before you call SetObjects? The error message indicates that the entity token can be missed in the http header.

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.