Page 1 of 1

Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Thu May 21, 2015 7:20 am
by Richard Edwards

Hi

Hope you can help. I've followed your instructions on on how to build an app with the Facebook api, which I am using to log users in to my app.

On my app, if a user logs in via Facebook for the first time, I then automatically use the new user's details to create a user in the User collection (using their email address returned via Facebook as their username, and generating a random password), and I receive back in the response a user _id and a sessionToken. I store these locally and can use them to do things in my app, such as allow users to update their user profile.

So far all is good.

However, if a user logs in later via Facebook I don't know how to get a new sessionToken for them. This means I also can't query the Users collection to get their user _id. Unfortunately, this means users can't do many of the things in my app like update their user profile.

How can I get a sessionToken for returning users who are logging in via Facebook?

Many thanks in advance,
Richard


Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Fri May 22, 2015 4:52 pm
by Serhii Kulibaba

Hello Richard,

Please create "sign in" service: https://devcenter.appery.io/documenta...
It returns user's _id and sessionToken


Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Wed May 27, 2015 12:52 pm
by Richard Edwards

Hi Sergiy

Thanks for replying. Unfortunately that doesn't work in this instance because the user is returning via Facebook, so they never use this "sign in" service and never get a sessionToken. This means they can't edit their own object in the Users collection.

To fix this, I'm trying to create a server-side sign-in script which takes their Facebook name and email address, creates a random password, adds them to the Users collection, then uses this information again to sign them in. This finally generates a sessionToken which will be passed back to the user.

That's the plan, anyway... :)

R


Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Wed May 27, 2015 3:06 pm
by Richard Edwards

Hi again,

Hmm.. Not v successful. Can you help?

Assuming I have the user's username and password, how does a server-side login code work?

I have the following:

code
var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/login" {
"headers": {
"X-Appery-Database-Id": dbId,
"Content-Type": "application/json"
},
"body": {
"username": username,
"password": test
}

Code: Select all

   }); 

/code

But I keep getting the error "SyntaxError: Unexpected token { ( @ 25 : 77 ) - var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/login" {"

Also, assuming I can get it to work, how can I create a sessionToken from this and return it to the user?

Many thanks,
Richard


Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Thu Jun 04, 2015 3:45 pm
by Serhii Kulibaba

Sorry, it was incorrect link. This is what you need: https://devcenter.appery.io/documenta...

Please use facebook plugin which returns facebook access_token from Facebook_Me service


Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Wed Dec 23, 2015 5:32 pm
by Howard Chang

Hi Sergiy/Richard,

I am trying the same thing and found this post. The link is no longer working. I am also writing some server code to get the login token for User Collection after facebook login.

Code: Select all

  var XHRResponse = XHR.send("GET", "[url=https://api.appery.io/rest/1/db/login]https://api.appery.io/rest/1/db/login[/url]", { 
         "headers": { 
             "X-Appery-Database-Id": dbId, 
             "Content-Type": "application/json" 
         }, 
         "parameters": { 
         "username": username, 
         "password": password 
         } 
        }); 

How do I get the response with the token and _id return? Thanks in advance for your quick response.


Returning users logging in via Facebook API - how to get a sessionToken?

Posted: Fri Dec 25, 2015 12:52 pm
by Serhii Kulibaba

Hello Howard,

You can get user's information from the Facebook_Me service or use access_token for any other requests to facebook