question

info-8 avatar image
info-8 asked

How do I use SessionTicket with Unity?

Hi there,

I'm tinkering around with playfab for users + leaderboards in my game atm. I can login and register users fine and I get a SessionTicket back and I store that. I can even make calls to GetPlayerCombinedInfo and get some stats, great.

However, whenever I use the client API to try to get any leaderboard data (using GetLeaderboardAroundPlayer for example) I keep getting an error saying

Must be logged in to call this method

I know I must have to pass that SessionTicket back somewhere but the *very* sparse documentation makes no mention of where I do that exactly, can someone point me in the right direction please?

Thanks in advance

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

All Client API calls, apart from login and password reset, require the Session Ticket as the "X-Authentication" header, as shown in all sample requests in our documentation (ex: https://api.playfab.com/documentation/client/method/GetLeaderboard). In addition, all of our SDKs take the Session Ticket from a successful login response and store it locally, re-using it automatically on all subsequent Client API calls, for convenience. Our Postman collection (https://github.com/PlayFab/PostmanCollection) also demonstrates usage of the X-Authentication header in all the client calls where it is needed, and provides instructions on setting up your own local environment variables, so that you can simply select the Session Ticket in the response from a login and right-click to set it up as the correct variable ("SessionTicket").

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

info-8 avatar image info-8 commented ·

But all your examples with x-auth are for standard rest requests, how do you specify that header with the API? None of your recipies or tutorials demonstrate it for c#/

0 Likes 0 ·
brendan avatar image brendan info-8 commented ·

As I said, if you're using one of our SDKs, you don't have to - we automatically copy the Session Ticket from the response and use it to create the correct header. For example, have a look at how _internalHttp.AuthKey is used in our UnitySDK: https://github.com/PlayFab/UnitySDK

0 Likes 0 ·
Denzie Gray avatar image Denzie Gray brendan commented ·

@Brendan

Is the ticket included in the Photon Webhooks & Client ExecuteCloudScript()?

If so, would one need an AuthCookie or would it be enough to check for the ticket in those calls?

0 Likes 0 ·
1807605288 avatar image
1807605288 answered

In most of our SDKs the sessionTicket is automatic and does not require any action by you.

  1. Every time the program starts, Log in, using any login method.
  2. You can then call every client API method you want for 24 hours or until the process is stopped.

We store the sessionTicket for you, you do not need to save it yourself, and in most cases, doing so is not advised. Do not attempt to put that into any request or headers, as none of our SDK interface expects you to manage this value.

Are you restarting the process without logging in again? (you have to log in again every time the process starts)

"Restarting" includes changing the code while your Unity Editor is open.

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

Denzie Gray avatar image Denzie Gray commented ·

@Brendan

Is the ticket included in the Photon Webhooks & Client ExecuteCloudScript()?

If so, would one need an AuthCookie or would it be enough to check for the ticket in those calls?

0 Likes 0 ·
pagilmor avatar image pagilmor Denzie Gray commented ·

Cloud Script is executed on behalf of your game, as a server process, and authentication/authorization occurs automatically before your function is called. No client or entity token is required. There is no need to authenticate. There are no tickets or cookies.

0 Likes 0 ·
Denzie Gray avatar image Denzie Gray pagilmor commented ·

@pagilmor

Are you saying that PlayFab will block illegitimate calls to the code on the server?Including the webhooks associated with Photon like CreateRoom?

I am currently in this thread trying to make an AuthCookie:

https://forum.photonengine.com/discussion/comment/52839/#Comment_52839

Is the above necessary?

Thanks in advance.

0 Likes 0 ·
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.