question

Dmitry avatar image
Dmitry asked

Login best practice

I have a question about Login best practice. In my application, I support login using Google, Facebook, and Apple.

I always log in using DeviceID first

  PlayFabClientAPI.LoginWithAndroidDeviceID(
                 new LoginWithAndroidDeviceIDRequest
                 {
                     CreateAccount = true,
                     AndroidDevice = SystemInfo.deviceModel,
                     OS = SystemInfo.operatingSystem,
                     AndroidDeviceId = SystemInfo.deviceUniqueIdentifier
                 },

Let's take Facebook as an example.

Suppose there is Device A. I log in to Device A using DeviceID with PlayFabClientAPI.LoginWithAndroidDeviceID and link it to Facebook using PlayFabClientAPI.LinkFacebookAccount.

Next, on Device B, I log in using DeviceID, and call PlayFabClientAPI.LoginWithFacebook. This way, I can retrieve shared data.

  • When I call PlayFabClientAPI.LoginWithFacebook on Device B, should I only use Facebook for future logins on Device B?

  • Can I save the Facebook AccessToken on Device B to automatically log in the user?

  • What should I do when the AccessToken expires? Should I prompt the user to log in again using Facebook?

Authentication
10 |1200

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

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

May I know why do you always log in with DeviceId first? If you want to use DeviceId login to simplify the player login process. The common way is that

  1. The player creates an account on device A with LoginWithXXXDeviceID

  2. Then the player can link a recoverable account such as Facebook or Google to this account

  3. When the player wants to play on Device B, they can log in with recoverable login method like LoginWithFacebook on Device B first

  4. Then link the DeviceId B to this account. In this way, the player can use the B’s DeviceId to automatically log in to device B

>>When I call PlayFabClientAPI.LoginWithFacebook on Device B, should I only use Facebook for future logins on Device B?

As we mention above, you can use LoginWithXXXDeviceID to simplify the player login process. And you can use any linked login methods as well.

>>Can I save the Facebook AccessToken on Device B to automatically log in the user? What should I do when the AccessToken expires? Should I prompt the user to log in again using Facebook?

It’s not recommended to store AccessToken locally. And as we mentioned above, you can use the B’s DeviceId to call LoginWithXXXDeviceID to automatically log in the user.

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

Dmitry avatar image Dmitry commented ·

Yes, I always use DeviceID login to simplify the login process. And only if the user wants to transfer data to another device, they can link it to Facebook, for example.

Then link the DeviceId B to this account. In this way, the player can use the B’s DeviceId to automatically log in to device B. I didn't understand how to do this point.

Let's say the user linked their Facebook account on Device A. Then they logged in to Device B using Facebook. How can I link DeviceID B to this Facebook account? What API method should I use? If I call LinkFacebookAccount, it will give an error "AccountAlreadyLinked."

0 Likes 0 ·
Dmitry avatar image Dmitry commented ·

Something like that?

 private void LoginWithFacebook(string accessToken)
         {
             PlayFabClientAPI.LoginWithFacebook(new LoginWithFacebookRequest {CreateAccount = true, AccessToken = accessToken},
                 loginResult =>
                 {
                     PlayFabUserId = loginResult.PlayFabId;
                 }, error =>
                 {
                 });
         }
    

 PlayFabClientAPI.LinkCustomID(new LinkCustomIDRequest
 {
     CustomId = PlayFabUserId, 
     ForceLink = true 
 }, OnLinkCustomIDSuccess, OnLinkCustomIDError);
0 Likes 0 ·
Xiao Zha avatar image Xiao Zha Dmitry commented ·

You can use LinkAndroidDeviceID to link the Device B to this Facebook account.

0 Likes 0 ·
Dmitry avatar image Dmitry Xiao Zha commented ·

@Xiao Zha After I linked DeviceID B using LinkAndroidDeviceID, I can't retrieve data from the Facebook-linked account (DeviceID A).

  1. Device A - calls LoginWithAndroidDeviceID (creates a new account).

  2. Device A - links the Facebook account.

  3. Device B - calls LoginWithAndroidDeviceID (creates a new account).

  4. Device B - logs in with the Facebook account.

  5. Device B - calls LinkAndroidDeviceID.

I use PlayFabClientAPI.GetUserData after authentication to retrieve user data. If I sign in with Device B device Id, I can't access data from the Facebook-linked account; instead, I get data from the Device B account. However, if I sign in with Facebook on Device B and then call PlayFabClientAPI.GetUserData with the obtained PlayFabId, I receive data from the Facebook-linked account.

 PlayFabClientAPI.GetUserData(new GetUserDataRequest
  {
  PlayFabId = playFabId,
  Keys = null
  }

If I used LinkAndroidDeviceID on Device B, why can't I retrieve data from the Facebook-linked account?

1 Like 1 ·
Show more comments

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.