Search Unity

Question Automatic authentication? What is the point of the Session Token?

Discussion in 'Authentication' started by Calthies4, Aug 5, 2022.

  1. Calthies4

    Calthies4

    Joined:
    Jan 18, 2017
    Posts:
    12
    I've been working on implementing Google sign in with my game, with the main goal being to allow cross platform cloud saves. Starting with a windows desktop app because that is the simplest.

    I got sign in with Google to work... however now that I have that working, I have a number of questions. I was expecting there to be some mechanism to allow you to automatically sign in a user, assuming they have signed in before and linked their google account. I wouldn't want a user to have to manually sign in every time the start up my game. I don't see anything in the documentation or authentication methods to support this.

    Am I supposed to store their google ID token locally, then pass that in to the sign in method on start up of the game? I figured there would be a built in way to handle things like this, so I've been hesitant to start building my own solution for something like that. If this is something the developer is expected to handle themselves, I think it would be helpful to indicate that in the documentation, and maybe even provide an example or design pattern to follow.

    On the same note, I thought that maybe the Session Token stored in PlayerPrefs would be useful in some way for logging the user in again, or something similar. However, I haven't been able to find a use for the session token, and the documentation is unclear on what it is used for. All it mentions is where it is stored in PlayerPrefs. Can someone enlighten me on what the point of the session token is? I assume it has to have some use beyond merely indicating that the user has a valid session due to the fact that it is stored in PlaeyerPrefs.
     
  2. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    494
    I assume storing the session token locally is the way to go, because I haven't yet found a way around that either. I hope someone from Unity (or of course any other knowledgeable person) is able to bring some light into the darkness.
     
  3. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    282
    Hi there,
    Thanks for taking the time to post on the forums.

    When you have a moment please visit the following link:
    Using the method below SignInAnonymouslyAsync() should attempt to sign you back into previously signed into google accounts.
    https://docs.unity.com/authentication/UsingAnonSignIn.html “If a player has already signed in before, the SignInAnonymouslyAsync() method recovers the existing credentials of a user whether they signed in anonymously or through a platform account. If there is no user sign-in information, this method creates a new anonymous user.”

    .
    You can see the overall sign in logic on the following page:
    https://docs.unity.com/authentication/BestPractices.html

    Please let me know if this isn't clear, Or have any trouble getting this to work. We would love your feedback and how we can improve the documentation.

    Additional links that may be of interest.
    https://docs.unity.com/authentication/SessionTokenManagement.html
    https://docs.unity.com/authentication/ProfileManagement.html