question

Jon avatar image
Jon asked

Entity Token / Session Token Expiration

What is the recommended way to check if the entity token / session token from login is not yet expired?

I think they last 24 hours, but would prefer a programmatic way to refresh / check this instead.

For example, if a user awakens the app, we would like to check if the token is still valid - if not, then sign in again. There is some processing time with our login logic so we would like to avoid logging in multiple times if the user token is still valid.

Thanks

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

·
Rick Chen avatar image
Rick Chen answered

In the login result, there is a TokenExpiration parameter under the EntityToken, which represents the time the token will expire, in UTC. You could store it locally check whether the token has expired by comparing the current UTC time with this parameter. And when it expires and you refresh the login, you also refresh the TokenExpiration stored locally.

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

andrearossini avatar image andrearossini commented ·

Is this valid also for ClientSessionTicket?
Many API calls use AuthType.LoginSession writing the ClientSessionTicket instead of EntityToken.

The EntityToken 'TokenExpiration' property is also valid to check the ClientSessionTicket expiration or should we check something else?

I'm asking this because every piece of code that use EntityToken is under a specific define (#if !DISABLE_PLAYFABENTITY_API), so I'm assuming I can use PlayFab SDK also with that define enabled.

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ andrearossini commented ·

Yes. The session ticket has a 24 hour lifetime, the same as the entity token. Therefore the TokenExpiration is also valid for the client session ticket. You could refer to this thread: https://community.playfab.com/idea/224/205582298-Session-ticket-expiry-Timestamp-.html.

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.