authtoken - session login

Hi!

I am having some trouble using the authtoken for session login. It works good to login with e-mail and password, I get the e-mail verification and have clicked that link as well. I stored the authtoken in a file which I load up and use it to log in:

local loginParams = {} loginParams.type = "session" loginParams.authToken = storyboard.state.authToken[2] cloud.login( loginParams )

but nothing happens. The authListener for cloud dosent even get called. Am I missing something here? I can register and login with mail and password, but nok with token.  I save the token after logging in successfully with “loggedIn” using: cloud.authToken

Guess I can always just store the email and password instead, but just wondered if there was something I was missing so I could correct it.

Hi,

The process is that you login with username/password to retrieve the auth_token.

At this point you don’t need to login again, you just need to pass the auth_token when you are making calls.

Thanks

-Mohamed

so you dont use the authtoken to log in? but the manage cloud users guide say that is one of the ways of logging in? Its not that its a problem, using email and password instead works fine. Just want to have it clear :slight_smile: Thanks!

Yes, I wondered that myself.

I was not sure I am making everything right so I didn’t post, but I can confirm the session login does not work.

It would be the preferred way for most users I guess, they would not be happy if they know you are storing their password somewhere on the phone.

Not sure I understood you correctly, but you don’t actually need or should store the user’s username and password.

All you need to store is that auth_token, which as I mentioned you can pass it with the calls so the data is associated with that user.

Hope that makes sense.

Can you let me know what you mean by the session login does not work?

Thanks

-Mohamed

When the user quits the game and returns later, I have a button “Last user” which should login the last player automatically (so he must not enter the email/password every time, as we have for the simulator - boring).

For this scenario I thought I will use this :

<docs>

Session Login

Once a user is registered and logged in, you can save the authToken
and, in future sessions of the app, log the user in using the token.
Alternatively, you can store the user’s email and password and use them
to log in the user as shown under Email/Password Login above.

local loginParams = {}

loginParams.type = “session”
loginParams.authToken = currentAuthToken

cloud.login( loginParams )

If the login is successful, the authListener() function will be called with an event type of “sessionLoggedIn”.

</docs>

So in the docs you suggest we can store the emaail/password and then use it for later login, what I did because the session login does not work (if I call the above code no event is triggered).

Hope this clarifies what we mean.

yeah, what ubj3d says. I also have a function that logs in the previous user so they dont have to do the login/password every session. But that dosent work with the authtoken session login as described. so now I have to store e-mail/password until I can get authtoken to work.

I’ll discuss with the team and get clarification on this.

In the mean time, I can assure you that you don’t need to store the username and password, all you need is the authToken.

In other words, you don’t need to pass the username/pw again get the authToken, you can continue using the one you received on first log in.

Sorry about the confusion.

Thanks

-Mohamed

I just got this working recently, and this is what I noticed. Maybe this will help. 1. Are you still calling cloud.init? I don’t see it in the little sample of code above, so just making sure. 2. For authToken, are you checking for event.type “sessionLoggedIn”? 3. If you are using storyboard, your require variable has to be the same name. I had cloud = require “cloud” in one scene and coronaCloud = require “cloud” in another scene. The authToken was not available in my scene with coronaCloud defined since I called the init with cloud. Hope this helps. If not, post your listener.

Wow.

As strange as this is… logging in via authToken is no longer working for me.  :frowning:

I had no problem for several days, and now I have the exact same problem.  My auth listener is never called when trying to log in via authToken.  Loggin in via email/password does work as expected.

Any update on this topic?

The same problem here, token login never work.

Hi guys,

I have asked the team to looking why this is happening, I will keep you posted.

Thanks

-Mohamed

What messages are you getting in your console log? Do you have debugging on for the cloud to get more messages on what’s going on?

as stated above by me and others, nothing is happening. no error, no output, nothing. and I have tried it with cloud.debugEnabled = true

if this should work and others are getting this to work then it would be great to se some code of this.  Currently I am saving email and password for login.

Hi,

While Rob is looking into this, may I suggest that instead of saving the email and password, save the auth_token only.

Then you don’t have to login, just load the auth_token and pass it with your calls.

-Mohamed

Can you post your code please?

Here is what I have… somewhat cleaned up.  Maybe others in this thread can post some code as well.

[lua]

cloud = require “cloud”

function ccLoginListener(event)

    if event.type == “sessionLoggedIn” or event.type == “loggedIn” then

        if not event.error then

              – do stuff like get achievements

              print “No errors”

        else

            alert = native.showAlert(“Error”, event.error, {“OK”})

        end

    end

end

cloud.init(ACCESSKEY, SECRETKEY, ccLoginListener)

cloud.login({type = “session”, authToken = PREV_SAVED_TOKEN})

[/lua]

Now, if I replace the cloud login command with this…

[lua]

cloud.login({type = “user”, email = MY_EMAIL_ADDR, password = MY_PASSWORD})

[/lua]

… then the event listener is called.  Using the session login, the listener is never called.

I have Lua Glider, and placed a breakpoint inside ccLoginListener, and it is never trapped when using session login.  I just tried it with build 2013.1095, and previously with 2013.1080

–john

I took a look at the cloud.lua file to try and figure out what happens when you do a session login. And from what I can see the only thing that gets done is that cloudCore.authToken = params.authToken. So, you are in fact logged in after a session login. I tried just calling: cloud.getProfile() and it worked. The problem I had was that I am checkin if cloud.isLoggedIn, and that returns false.

So the issue I am having with session login is that there is no feedback that you are infact logged in.  the cloudCore.isLoggedIn never gets set when doing session login, because only facebook and user login seem to make any calls here:

    if params.type == “facebook” or params.type == “user” then

        _postCC( path, pathParams, networkListener )

    end

Not sure if this is right or not, just what I think might be the issue. Someone with more knowledge could maybe look it up :slight_smile:

Here is the way this works. Al cloud API calls that require the app to be logged in uses this auth token as a hidden parameter in all their calls. You don’t have to pass it to multiplayer.getMoves for instance. If you are not logged in, you login via email or Facebook and the cloud provides you an auth token. From the clouds perspective that token is good forever and you never have to login again if your app doesn’t exit (crash, killed by user, exit button on android, etc.) If you save the auth token and if you start up, you call the session based login. It does not reachi out to the server or do anything more than making the auth token available to the API calls like you never left. So there won’t be any call to the auth listener. If you have a valid auth token and once you set it, you are good to go. Hope this helps. Rob

Hi Rob,

Thanks for the clarification.  It does help, and I appreciate the reply.

I guess what was confusing to everyone is that the documentation states that a cloud.login call with the “session” parameter will return a “sessionLoggedIn” event to the listener, and that is not happening… although I do understand why now.

In my listener, I set a lot of variables based on a successful login, but based on your latest message, I guess the method that will work is to set cloud.authToken with the saved token, and to assume that login is successful, therefore set the variables I need to set.

I have confirmed that setting authToken does in fact return achievement and leaderboard details when called.