question

Arjuna avatar image
Arjuna asked

What's a good login workflow for Unity

Where can I find a good example of a good Authentication and log in workflow in Unity. 

i.e. I want the user to create a custom ID the first time. Later in the game I will prompt them to link to Facebook, Google or Email. 

What's the best way to store the session variable, and how do I use it to log in on subsequent app starts. How do I handle if the last user was using a custom ID, Facebook ID or other?

Do I need to handle expiring tokens etc? How do I keep the process friction-less for the user? I don't want a sign in dialog box to come up other than when linking accounts. 

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

·
brendan avatar image
brendan answered

Well, we have a blog post on recommended authentication paths here: https://playfab.com/blog/first-impressions-count-best-practices-friction-free-player-authentication/.

But the short version is, yes, we recommend using low- or zero-friction sign-in to start, followed by incentivized linking to other account systems, like Facebook and Google. Device IDs are relatively simple to retrieve on subsequent playthrough, and with Custom ID, your best bet is to store the ID locally, so that you can re-use it.

You definitely do need to handle expiring tokens, since you should be saving the session ticket locally, and reusing it when the player comes back into the game. When it expires, you'll want to re-authenticate the player in the simplest way possible, so that you're not interrupting the player experience.

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

Arjuna avatar image Arjuna commented ·

Thank you, that was a really useful link!

0 Likes 0 ·
Jacques Leemans avatar image Jacques Leemans commented ·

@Brendan, you mention "save the session ticket locally", how can I set the session ticket on the PlayFabClientApi calls? I want to make testing easier, so I want to sign in once in 24 hours, save the ticket (PlayerPfres in Unity), and then call any client API, but it doesnt seem like there is a way to set the session ticket, something like:

SetSessionTicket or something would be useful

0 Likes 0 ·
brendan avatar image brendan Jacques Leemans commented ·

Yes, the Session Ticket is stored as AuthKey in the SDK, so the call you want is SetAuthKey in PlayFab.Internal: https://github.com/PlayFab/UnitySDK/blob/6746e182851962aad4505fafc0acb4d0a95a0f65/Source/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs.

0 Likes 0 ·
Jacques Leemans avatar image Jacques Leemans brendan commented ·

Thanks @Brendan

0 Likes 0 ·
Jacques Leemans avatar image Jacques Leemans commented ·

Hi Brandan, using SetAuthKey throws a NullReferences exception (_internalHttp), do we first need to create a HttpClient Object?

0 Likes 0 ·
brendan avatar image brendan Jacques Leemans commented ·

Which HTTP Request configuration are you using?

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.