question

George Chernikov avatar image
George Chernikov asked

Lots of NotAuthenticated errors on Kongregate

Hi there -

I'm running into a lot of NotAuthenticated errors on Kongregate. I read this post and added handling for when these errors occur - whenever the error is raised, the game attempts to re-authenticate with PlayFab. In spite of this, issues continue arising, in response to the UpdateUserData request (which is what the save game function does).

Any ideas? Aside from being a major pain to the users, it also stops me from implementing hard currency rewards, as I'd like those to be managed by the server - which is problematic if I cannot rely on the server correctly crediting the reward due to an authentication issue

    public static void SaveGameOnline(Action<bool> callback)
    {
        GetServerTime((time) =>
        {
            Debug.Log("Received server time of " + time.Time.TimeOfDay);
            UpdateUserDataRequest request = new UpdateUserDataRequest { Data = SaveGameManager.GetSaveData(time.Time.Ticks) };
            PlayFabClientAPI.UpdateUserData(request, (result) => { callback?.Invoke(true); }, (error) => { callback?.Invoke(false); OnSaveGameError(error); });
        });
    }


   public static void GetServerTime(Action<GetTimeResult> callback)
    {
        PlayFabClientAPI.GetTime(new GetTimeRequest(), (result) => callback?.Invoke(result), (error) => { if (error.Error == PlayFabErrorCode.NotAuthenticated) { ReauthenticateUser(); } });
    }


    private static void OnSaveGameError(PlayFabError error)
    {
        if (error.Error == PlayFabErrorCode.NotAuthenticated)
        {
            ReauthenticateUser();
        }


        if (error.Error == PlayFabErrorCode.EntityTokenExpired)
        {
            ReauthenticateUser();
        }
    }


    private static void ReauthenticateUser()
    {
        var kongregateLoginRequest = new LoginWithKongregateRequest { KongregateId = kongregateID, AuthTicket = kongregateAuthTicket, CreateAccount = false };
        PlayFabClientAPI.LoginWithKongregate(kongregateLoginRequest, null, null);
    }
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

After the client calls the LoginWithKongregate successfully, they need to call UpdateUserData again. We need to implement such a loop that verifying the response, updating data then verifying the response, until users’ data is updated successfully.

privatestaticvoid ReauthenticateUser()
{
LoginWithKongregateRequest kongregateLoginRequest = new LoginWithKongregateRequest { KongregateId = kongregateID, AuthTicket = kongregateAuthTicket, CreateAccount = false };
PlayFabClientAPI.LoginWithKongregate(kongregateLoginRequest, OnLoginSuccess, OnLoginFail);
}
privatestaticvoid OnLoginSuccess(LoginResult obj)
{
// UpdateUserData
}
privatestaticvoid OnLoginFail(PlayFabError obj)
{
}
4 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.

George Chernikov avatar image George Chernikov commented ·

Hi Sarah -

Many thanks for your reply. If I understood correctly, you're suggesting calling a UpdateUserData upon a successful login or reauthentication. Are you saying that there is some sort of a connection between calling UpdateUserData and resolving the NotAuthenticated error (e.g., does UpdateUserData need to be called to "establish" authentication)?

Just to clarify: my intention in the current implementation is that updating user data is done as part of the autosave. In case the update fails due to the authentication error, the game attempts to reauthenticate. Then when the next autosave triggers - a minute later - UpdateUserData would be called for a now-reauthenticated client.

To be clear, my goal is not to have a solution where a successful resolution of the NotAuthenticated error leads to an immediate UpdateUserData call (it's nice to have, but it's not the issue). My issue is that NotAuthenticated errors keep cropping up even after the reauthentication call has been made upon receiving the error.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang George Chernikov commented ·

No, it doesn't. I suggested calling UpdateUserData after players login successfully because I didn't get the point it's an auto-save mechanism before.

The question I wondered is how do you make sure the clients login successfully in the ReauthenticateUser()? It seems that you did not define the OnLoginSuccess callback function.

0 Likes 0 ·
George Chernikov avatar image George Chernikov Sarah Zhang commented ·

Hi Sarah -

I don't think I was very clear in my original post - my apologies.

The expected functionality is that calling the LoginWithKongregate method should result in the user being authenticated for subsequent interactions with the PlayFab service.

        var kongregateLoginRequest = new LoginWithKongregateRequest { KongregateId = kongregateID, AuthTicket = kongregateAuthTicket, CreateAccount = false };
        PlayFabClientAPI.LoginWithKongregate(kongregateLoginRequest, null, null);

When I subsequently call any function that required interacting with the server - such as updating user data and/or getting time, it often (10% of the time) fails with the NotAuthenticated error. In such cases, I call the ReauthanticateUser() method to re-establish authentication.

The expected functionality is that all future calls to the server should succeed - as the NotAuthenticated error will have been handled via re-authentication. The actual functionality is that server interactions continue to fail with the NotAuthenticated error, even after a re-authentication.

My question is, what's causing the issue and what can I do to avoid it?

0 Likes 0 ·
Show more comments
George Chernikov avatar image
George Chernikov answered

@Sarah Zhang - According to PlayFab's title overview chart, the LoginWithKongregate call returns "Success" 99.99% of the time, whereas NotAuthenticated errors appear constantly.

2 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.

Sarah Zhang avatar image Sarah Zhang commented ·

We will try to reproduce it on our own titles.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang commented ·

We created and tested the LoginWithKongregate sample(added the update user data feature), it works fine. It seems not a PlayFab API issue, could you try to check the client code in depth?

0 Likes 0 ·

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.