Search Unity

Question Failed to load config from cache.

Discussion in 'Authentication' started by TheEugeneL, Jan 2, 2022.

  1. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    Hello,

    I've implemented your Unity Authentication Beta service into my project, and I am using Anonymous Authentication. But unfortunately I got some problems.

    On a new project and everything works without errors. But on my current project I always get the following error:

    Failed to load config from cache.


    Authentication works good, but after some time I get new error:
    [Authentication]: Request failed: 401, {"title":"INVALID_SESSION_TOKEN","detail":"The session token is not valid.","details":[],"status":401}


    In both cases I use the same version of Unity. Both versions are connected to the same project in Unity Dashboard. I tried reinstalling packages but that didn't help.

    Is it possible I am missing something?

    Unity version: 2020.3.9f1
    Mac OS Catalina 10.15.7
     
    Last edited: Jan 3, 2022
  2. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    Hi There,

    Thanks for implementing the Authentication Beta, sorry to hear that you have run into an issue.

    We will likely need some more details on your current project, where you are getting the error. But, a couple of things to check first.
    1. Are you clearing the PlayerPrefs on your existing project?
      You might want to take a look at the Player Prefs and Authentication Session sections of the documentation just incase that is where the issue is?
    2. You have confirmed that both your projects are linked to the same Unity Project Dashboard. Are you using the same Build settings on each of your tests? What do the Unity Editor > Edit > Project Settings > Services > Authentication settings look like? You don't by any chance have different ID providers assigned for each of the procjects.
    Please let me know if either of those help to resolve the issue. If not, please DM me a link to your Project's dashboard and a copy of each of your projects Packages > manifest.json file.
     
  3. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    Hello, thank you for your answer!

    I'm getting the error, about failed to load config from cache, when run play mode. Then I see usual logs like:
    Unity services initialization: Initialized
    Cached Session Token Exist: True
    Sign in anonymously succeeded!
    PlayerID: uha947yorFIIBkWdXaedbCFJOseP


    As you can see above, I checked the Cached Session Token:
    AuthenticationService.Instance.SessionTokenExists

    and it's true every time. Even when I'm getting the error about invalid token, status:401.

    About things to check:
    1. I'm not clearing the PlayerPrefs because I'm not using the PlayerPrefs in my current project. But I tried to do it, and it didn't help me.
    2. Yes, I'm using the same Build settings on each of my tests.
    Editor > Edit > Project Settings > Services > Authentication settings look same with only one apple provider. And I was getting this error before adding any provider.

    Also a few days ago I got the error about invalid token three times during the day. But yesterday and today sign in is working fine. I have the message about failed to load config from cache only.

    Screenshot with my logs:
    Screen Shot 2022-01-03 at 5.03.47 PM.png
     
  4. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    Today I got the error about a token again.
    [Authentication]: Request failed: 401, {"title":"INVALID_SESSION_TOKEN","detail":"The session token is not valid.","details":[],"status":401}


    I can fix it only with
    AuthenticationService.Instance.ClearSessionToken();
    and sign in like a new user with lost all of the progress.

    Screen Shot 2022-01-03 at 7.35.39 PM.png
     
  5. randyl_unity

    randyl_unity

    Unity Technologies

    Joined:
    Aug 22, 2019
    Posts:
    7
    Hi!
    Thanks for raising the issue TheEugeneL. I have a few thoughts + clarifying questions from your observations.

    "Both versions are connected to the same project in Unity Dashboard."
    What does this sentence mean? It reads to me like you are testing the same Unity Project on two different Editor versions, but I want to confirm my understanding with you.

    "On a new project and everything works without errors. But on my current project I always get the following error".
    Can you please clarify what you are referring to by "project"? There are a lot of uses of the term "project", so I just want to confirm my understanding.

    Authentication is separate from Remote Config, so the cache load error message is likely a separate issue from Authentication.

    If your testing relies on persisting progress, I would not suggest relying on anonymous login (particularly for Play Mode testing). I would suggest using a third party login for more predictability. Delete/unlink APIs are available with the latest release of the Authentication SDK, so you can easily reuse/recycle the third party account.

    I still don't quite understand the repro steps. Can you please provide exact repro steps?

    AuthenticationService.Instance.SessionTokenExists only checks if the session token string is not null, so the behavior you saw is expected.
     
  6. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    "Both versions are connected to the same project in Unity Dashboard."
    I have new empty project and the game I'm working on right now. And both of them I connected to the same project in Dashboard.
    Editor > Edit > Project Settings > Services

    "On a new project and everything works without errors. But on my current project I always get the following error".
    I'm referring to by "project" which you can create or open using the Unity Hub.

    "Authentication is separate from Remote Config, so the cache load error message is likely a separate issue from Authentication."
    Yes, it could well be. I just noticed that in an empty project I don't get the cache load error message and I don't get the error about token is not valid either. That's why I assumed it could be related.

    "I would not suggest relying on anonymous login"
    I totally agree. In this case, I consider the possibility that the player can enter the game without a third party login. And only then choose whether he wants to authorize for synchronization on other devices or not.

    "I still don't quite understand the repro steps. Can you please provide exact repro steps?"
    1. I created a new project in Unity Hub and connected to the same project in Dashboard.
    2. Added packages through the manifest.json file for authorization.
    3. On the Package Manager > Authentication downloaded UI Example.
    4. Opened AnonymousLoginUIExample scene and run.
    5. Everything works great.

    For the existing project, I did the same thing except for the first step.
     
  7. randyl_unity

    randyl_unity

    Unity Technologies

    Joined:
    Aug 22, 2019
    Posts:
    7
    Thanks for the additional information and repro steps! A couple of things:

    That setup should be fine. On our end, we can't really see the difference.

    "Yes, it could well be. I just noticed that in an empty project I don't get the cache load error message and I don't get the error about token is not valid either. That's why I assumed it could be related."
    I'm pretty sure its a coincidence. The session token is from the Authentication SDK cache, so the stack trace should have the Authentication SDK's function in its path if that were the case. I'm not familiar with the Remote Config cache, but I do know its touching other remote config specific stuff.

    "I totally agree. In this case, I consider the possibility that the player can enter the game without a third party login. And only then choose whether he wants to authorize for synchronization on other devices or not."
    That definitely is a valid consideration.
    For Play Mode anonymous testing specifically, a consistent way to go about it would be to always initialize a Play Mode session with a new anonymous user and just treat each individual Play Mode run as an instance for a new user. This should yield consistent testing results.