question

Andy Maddison avatar image
Andy Maddison asked

Invalid/Expired Tickets

I'm just starting out with PlayFab on Unity and what I gather is that it's important to check for invalid/expired tickets on any call to the API.

There does seem to be a lack of definitive information though. For example, in the API docs for GetUserData there is only one possible error code, and that's InvalidParams, but as I understand the ticket related error codes can be returned too? So why aren't they given?

I downloaded your sample in the hope of finding out about ticket error codes but that doesn't handle them at all.

This forum post says that error code InvalidSessionTicket is returned but also to check for NotAuthenticated. I see there's also an error code for InvalidTicket, can this be returned? It just seems a little vague about what exactly the error codes can be for any particular call. Why is that?

Also, is they a way for me to invalidate the ticket so I can test my flow and actually see what error codes are coming back?

 

10 |1200

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

brendan avatar image
brendan answered

First, changing the ticket in any way (add or remove a character) would invalidate it. The tickets are also only valid for 24 hours, so retrying one which was created longer than that ago would also fail. I'll ask the tools team about getting the documentation clarified to reflect the specifics, but you should get back an HTTP status 401 (Unauthorized) in both cases, like so:

{
"code": 401,
"status": "Unauthorized",
"error": "NotAuthenticated",
"errorCode": 1074,
"errorMessage": "X-Authentication HTTP header contains invalid ticket"
}

10 |1200

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

Andy Maddison avatar image
Andy Maddison answered

So what is the best practice? Check for code 401? Or check error type?

After logging in I'll be likely doing GetUserData and UpdateUserData calls only for the time being. 

10 |1200

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

Andy Maddison avatar image
Andy Maddison answered

Can you explain how I modify the ticket? As far as I can see I get the ticket back in the LoginResult class but then I don't explicitly pass it through to GetUserData for example.  

10 |1200

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

brendan avatar image
brendan answered

You never modify the Session Ticket - you should pass it in as the X-Authentication header as-is (as a string).

For checking the error codes, I would always encourage checking for all the known errors. I've asked the tools team to review the API docs and update them to make sure all the error codes are called out for each call, so those should be up-to-date shortly.

10 |1200

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

Andy Maddison avatar image
Andy Maddison answered

 

I've managed to do what I want via Postman, i.e. get error codes back.

10 |1200

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

brendan avatar image
brendan answered

Great - glad to hear you've not blocked. And yes, we love Postman - very handy tool for testing. We provide a full Postman Collection of all our API calls, alongside our SDKs, as well: https://api.playfab.com/sdks/postman

10 |1200

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

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.