Search Unity

Question External Identity Providers with Unity Authentication and Cloud Save

Discussion in 'Cloud Save' started by Fantonim, Jan 15, 2023.

  1. Fantonim

    Fantonim

    Joined:
    May 30, 2019
    Posts:
    4
    A lot of this is confusing and I hope that someone can help me understand.

    The issue is, I followed the guide to enable Google and Apple sign-in for my Unity project:

    https://docs.unity.com/authenticati...24.1549076417.1673790983-508653245.1673790983

    What i'm confused about is When the user signs in via these External identity providers, does it also authenticate with Unity Game Services, and Cloud save? Does it give UGS a player ID and an access token automatically? How exactly does their Google sign in point to their player ID in the Unity Cloud save?
     
  2. devingunity

    devingunity

    Unity Technologies

    Joined:
    May 26, 2021
    Posts:
    33
    Hi Fantonim,

    Your understanding seems to be correct - when a user signs in using an external identity provider, the Authentication service assigns the player a UGS Player ID and access token. It is this ID and access token that are then used for any calls to Cloud Save - as far as Cloud Save is concerned there is no difference between players using different authentication methods, they are all processed using their UGS Player ID.

    As far as how specifically the external identity provider is connected to the player ID, this all happens on the Authentication level and so is outside of my expertise, but I'm sure someone would be able to provide more clarity in the Authentication forum!
     
  3. Fantonim

    Fantonim

    Joined:
    May 30, 2019
    Posts:
    4
    I see. Is this statement true? "In order to assign the player a UGS Player ID and access token using Apple devices, I must use
    Code (CSharp):
    1.  await AuthenticationService.Instance.SignInWithAppleAsync(token);
    2.  
    This function will create an UGS Player ID for the player if there isn't one already present in the Cloud save correct?

    Further, When i am logging in through apple, I am serializing the idToken from the IAppleIDCredential. And i am using this same idToken to check for CredentialState. Is this the same idToken that would be present in the CloudSave?


    Code (CSharp):
    1.  
    2. var loginArgs = new AppleAuthLoginArgs(LoginOptions.IncludeEmail | LoginOptions.IncludeFullName);
    3.  
    4.             this.appleAuthManager.LoginWithAppleId(
    5.                 loginArgs,
    6.                 credential =>
    7.                 {
    8.                     var appleIdCredential = credential as IAppleIDCredential;
    9.                     var idToken = Encoding.UTF8.GetString(
    10.                         appleIdCredential.IdentityToken, 0, appleIdCredential.IdentityToken.Length);
    11.                     // If a sign in with apple succeeds, we should have obtained the credential with the user id, name, and email, save it
    12.                     byte[] data = FileSerialization.SerializeObject(idToken);
    13.                     FileSerialization.WriteToFile(FileSerialization.userAppleID, data);
    14.                     UnityAuthService.Instance.SignInThroughUnity(idToken);
    15.                 },
    16.                 error =>
    17.                 {
    18.                     var authorizationErrorCode = error.GetAuthorizationErrorCode();
    19.                 });