question

georg avatar image
georg asked

Authentication with LuaSDK (with Corona)

Hey,

not sure if it's a rookie mistake but after an hour of going through various posts this is kind of my last hope. I'm trying to connect our project to the Playfab backend, we've built our app with CoronaSDK. I've activated the Playfab plugin and logging in works so far. My problem is, that whatever API call I make the debugger tells me I have to be logged in. Based on a couple of posts I thought I understood that the SDK will take care of session handling and that there's no need for setting headers. I haven't found an API call to check wether a user is logged in either.

Any guidance is highly appreciated.

Thanks in advance

Georg

sdksAuthentication
10 |1200

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

1807605288 avatar image
1807605288 answered

Reviewing your code:
The login is not complete when the Login function returns. Everything is Asynchronous. You can't call GetTime until the success callback has been invoked. You're basically doing this:

  1. Set up a Login Call (Async code will be run later)
  2. Set up a GetTime Call (Immediate check to see if you're logged in fails, throw exception)
  3. Execute the async login logic
  4. Successful login

See the order of operations error? Async callbacks do not execute immediately.

Alternate example for you:

I've just run the plugin from Corona, and everything worked successfully for me. So I'll give you my example source here, and hope that it helps you:

local pfClient = require("plugin.playfab.client")
local PlayFabClientApi = pfClient.PlayFabClientApi
PlayFabClientApi.settings.titleId = "144"


function OnSuccess(result)
    print("Congratulations, you made your first successful API call!")
    print("Logged in: " .. tostring(PlayFabClientApi.IsClientLoggedIn()))
    
    print("Running GetTime")
    PlayFabClientApi.GetTime({},
        function(cloudResult) print("GetTime Success") end,
        function(error) print("Your GetTime call failed\n" .. error.errorMessage) end
    )
end

local loginRequest = {
    -- https://api.playfab.com/Documentation/Client/method/LoginWithCustomID
    CustomId = "GettingStartedGuide",
    CreateAccount = true
}
PlayFabClientApi.LoginWithCustomID(loginRequest,
    OnSuccess,
    function(error) print("Something went wrong with your first API call.\nHere's some debug information:\n" .. error.errorMessage) end
)

Please note that: PlayFabClientApi.IsClientLoggedIn() exists, and returns a boolean you can check.

In a more game-ish example, you might add several buttons to the screen, bind an api call to each, and push each button one at a time. You still need to account for the async nature of the calls, and deal with the player button-mashing, or pushing buttons too quickly, but you'll see that the API calls take MANY game ticks to complete (5-20 game ticks, or 50-300ms depending on your internet quality). Your first login in particular can sometimes take upto 1 second.

For others which might have similar issues: note that if you're getting an error return, you might not be reporting it correctly. If your second call is reporting that you're not logged in, then perhaps the first call is invoking the error callback rather than the success callback.

1 comment
10 |1200

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

georg avatar image georg commented ·

Thanks @Paul Gilmore, the asynchronous hint was the missing piece. It looks like it's working now, many thanks for your help. @Brendan, thanks to you as well!

0 Likes 0 ·
brendan avatar image
brendan answered

Yes, in our SDKs any successful login results in the session ticket being set. The session ticket is required for all calls to the service by the client. That specific error would indicate that either the session ticket wasn't set, it was corrupted, or it has expired (they last for 24 hours). Can you confirm that you followed all the instructions in the readme (https://github.com/PlayFab/LuaSdk/tree/master/Corona) for using our Lua SDK with Corona? What version of the SDK are you using? Can you send us a Wireshark capture showing the details of the traffic?

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

georg avatar image georg commented ·

Thanks @Brendan.

yes, I followed the readme and the login part works. I have activated the plugin on the Corona market place, I can see the last update happened on Dec 7. Not sure how to find out the version though.

I can send a wireshark if you let me know what you're looking for.

Thanks

Georg

0 Likes 0 ·
brendan avatar image brendan georg commented ·

You can find the version number in the release notes reference in the SDK (ex: https://api.playfab.com/releaseNotes/#161121). What we'd be looking for in the Wireshark capture is the details of the request which is failing - what headers it uses, in particular.

0 Likes 0 ·
georg avatar image georg commented ·

We're using Corona, so the plugin is pulled from the Corona marketplace. I'm assuming it's the latest version you have submitted to the marketplace.

On the wireshark topic, I've checked and can't seem to find the traffic at all, even the successful login. I did some testing with postman and taking the session ticket returned from the login request through our app I can successfully use the other API end points.

0 Likes 0 ·
brendan avatar image brendan georg commented ·

Yes, if you've downloaded it since the December 7th update, you have the latest. The fact that you're not seeing any traffic is odd, though. What's the specific message you're getting from the debugger?

0 Likes 0 ·
georg avatar image georg brendan commented ·

Here's the error message:

ERROR: Runtime error Must be logged in to call this method stack traceback: [C]: in function 'error' ?: in function 'GetTime' main.lua:77: in main chunk

And here's my code:

local pfClient = require("plugin.playfab.client")
local PlayFabClientApi = pfClient.PlayFabClientApi
PlayFabClientApi.settings.titleId = "?????" <-- Replaced the actual title id


local loginRequest = {
    -- https://api.playfab.com/Documentation/Client/method/LoginWithCustomID
  TitleId = "??????", <--- Replaced the actual title id
  DeviceId = system.getInfo( "deviceID" ),
  CreateAccount = true
}


PlayFabClientApi.LoginWithIOSDeviceID(loginRequest, function(result) print("Login Successful: " .. result.SessionTicket) end, function(error) print("Login Failed: " .. error.errorMessage) end)  <-- This works, I can see the session ticket in the console

PlayFabClientApi.GetTime() <-- This doesn't work

0 Likes 0 ·
Show more comments
georg avatar image georg commented ·

Gotcha and glad we have the code on GitHub, the files pushed from the marketplace are encrypted. I've tried tracing the variable but as I don't have access to the code and the _internalSettings table is not exposed I haven't found a good way to debug the function calls.

What I've noticed though is that the two packages are slightly different when it comes to content. The package the Corona marketplace pushed through contained two files I didn't see on GitHub:

- PlayFabHttpsCorona.lua (https://github.com/PlayFab/SDKGenerator/blob/fc76973f541c6bf2ed64cb1e60e16c0826071d48/targets/LuaSdk/templates/Corona/PlayFabHttpsCorona.lua.ejs)

- defaults.lua

Not sure what's going on, I checked the code, at least the one that is on GitHub and it looks fine. Maybe there is a problem with the version coming from Corona, but as I said, I don't know how I would access the code.

0 Likes 0 ·
brendan avatar image brendan georg commented ·

Thanks - we'll have our tools team double-check the version in the Corona marketplace.

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.